Install multiple JDKs on Mac OS X

It so happened that after watching JDK 8 in action in the GIDS Summit i was very much interested in trying out some of the features of JDK8, but i wasn’t sure of installing JDK 8 on my Mac because of the fact that the project i am working on is based on JDK 6 and will Mac allow me to uninstall JDK 8 and reinstall JDK 6 and in the process my OS shouldn’t be corrupted. So I took a small risk and just tried out.

So in this post we shall see how to install multiple JDKs on Mac OS X, and also switch between them easily as and when required.

1. Verify the existing JDK installation

The command to verify the existing Java version is java -version  and which java is used to check the location of the java command.


Mac OS X 10.6 onward ship with JDK installed, here I have JDK 1.6 already installed.

2. Install JDK 7 & JDK 8

Now lets install JDK 7 and JDK 8, they can be downloaded from here as any other software installed on Mac.



3. Configure JDKs

Mac OS X requires us to set JAVA_HOME variable in ~/.bash_profile to /usr/libexec/java_home.  On executing the command /usr/libexec/java_home  -V we get the below output.

The above output states that there are four versions of JDK installed on the Mac.

Now lets edit bash_profile and export JAVA_HOME as below.

After changing the above and checking java -version we  get the below, which means that by default Mac OS has selected the latest version on JDK on the OS.

Lets edit the bash_profile again in order to point to JDK 7

build compile bash_profile and run java -version again

Now we have successfully switched to JDK 7, similarly for switching to JDK 6 we should say 1.6 instead and repeat the above steps.

I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.


  1. By Sundar


    • By Manjunath


  2. By Sundar


    • By Manjunath


  3. By Sundar


  4. By Sundar


    • By Manjunath


Leave a Reply

Your email address will not be published. Required fields are marked *