How to change the Java version on the Mac terminal

Bryan Siegel
January 7, 2023

So I’ve been learning Java and needed to change the version from 19 to 17. Well it’s super easy.

First open up your terminal and type in

/usr/libexec/java_home -V

and you should see the Java versions installed on your machine. Mine looks something like this

check Java version

You’ll notice that I have 19 and 17 installed. To switch to a particular version of Java all you need to do is type in

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

Then to check which version of Java that you’re running all you need to do is type in

 java -version

Tags

Java

Would you like to hire me?

Side projects, Employment Opportunities, you want to give me a [big bag] of money.

Contact