Switching Java (JDK) Versions on MacOS

Dev Sharma
Mar 26, 2019 · 2 min read

This tutorial will guide you on how to switch JAVA versions on your MacOS device. This can be useful for working with apps which don’t work with updated JAVA versions. For example, applications such as Cassandra will only work with JAVA version 8.

First, you need to make certain you have multiple JAVA versions installed.

  1. Open a new Terminal window and input:
/usr/libexec/java_home -V

Your output should look like:

Matching Java Virtual Machines (2):11.0.1, x86_64: "Java SE 11.0.1" /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home1.8.0_201, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home

Note that there are two JDKs available. If you don’t notice the Java version you need to switch to, download and install the appropriate one from here (JDK 8 is represented as 1.8) . Once you have installed the appropriate JDK, repeat this step.

2. Take note of the JDK version you want to switch to. For example, “11.0” and “1.8” are the JDK versions available in the example above.

3. Switch to the desired version. For example, if you wish to switch to JDK 8, input the following line:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

For 11.0, switch “1.8” with “11.0”

4. Check your JDK version by inputting into Terminal:

java -version

If you have followed all the steps correctly, the JDK version should correlate with the one you specified in the last step.

5. (Optional) To make this the default JDK version, input the following in Terminal:

open .bash_profile

Then, add your Terminal input from step 3 to this file:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Save and close the file.


Dev Sharma

Written by

MSc Analytics @ Columbia

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade