Change Java version in macOS

Assume, you are installing multiple Java versions in macOS, so how do you change from one version to another? In this tutorial, I will guide you to do this.

First, let’s open Terminal and enter the following command to check all the Java versions that we have installed:

Result:

Change Java version in macOS

As you can see, currently I am installing two versions of Java 8 and Java 9, the default is Java 9.

Change Java version in macOS

Now, I need to use Java 8 so I will switch to Java 8 as follows:

  • Copy the path that is installing Java 8, here’s: /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
  • Open the .bash_profile file located in the user directory, and then add the following line:

  • Save these changes.

For these changes to take effect immediately, you need to run the following command:

Result:

Change Java version in macOS

Add Comment