(Mac OS) JAVA version does not change

Solution 1:

Install sdkman which takes care of the rather tedious command line voodoo you have to employ to try to make this happen. The problem is, JAVA_HOME is just an environment variable, it changes nothing - only tools that explicitly look for it (generally, maven and ant for example) will be affected by messing with it. When you type java on a mac, it runs /usr/bin/java, which is not a file you can change even as root. This java will then invoke the real java, and does not look at JAVA_HOME to get the job done: It is a softlink to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java, and because it is in /System you can't change that either, not even as root.

That's why this is so hard, and why you want a nice tool (sdkman) to do it for you.

Solution 2:

The removal of quotes around the JAVA_HOME and then setting the path variable variable worked for me (Mac OS Catalina):

export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH