How to install open JDK8, JDK 11, JDK 12, on Mac OS and switch between them

udaiveer singh
Code Wave
Published in
3 min readJul 23, 2019

This blog post is for people that have not installed any JDK libraries before and want to know how. As a bonus, I will also go over how to switch between different java installations.

https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot

Step One) visit AdoptOpenJDK and follow the installation wizard. (pay attention as it tells you where it is installing java)

Step Two) confirm you have something in the following directory

/Library/Java/JavaVirtualMachines

VirtualMachines directory is an excellent place to put all your java installations. Each of these folders is a different java version (yes I have two java 11 version don’t judge me)

Step Three) let’s take java 12 or whichever version you have for a spin. Go ahead and grab the path of the java installation like so (remember your path will be different based on the version you install, but base folders are the same /Library/Java/JavaVirtualMachines/)

/Library/Java/JavaVirtualMachines/adoptopenjdk-12.jdk/Contents/Home/bin

the bin should have files like java; in fact, you should be able to do something like

Step Four)

Open up a file called .bash_profile, (if you don’t have one you have to create it). This file is the one that gets loaded each time you log on to your user.

using your favorite text editor (I will use vim) and add this line in there

now execute

source ~/.bash_profile
java -verison

you should now have java installed

Step Five) switching between java version

In the ~/.bash_profile

comment out the previous line and add the path for a different version of java you want to use

source ~/.bash_profile

Hopefully, this went smoothly, and now you can do some actual coding!

--

--