1

I can't see to set the correct version of Java to use, even though I have set JAVA_HOME correctly:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home/
$ java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    11.0.8, x86_64: "Java SE 11.0.8"    /Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home
    11.0.2, x86_64: "Java SE 11.0.2"    /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
    11.0.2, x86_64: "OpenJDK 11.0.2"    /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home
    1.8.0_202, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
    1.8.0_181, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home

How do I get the java command to use the correct JDK?

I'm on MacOS Mojave 10.15.6

I tried this solution, but it didn't work :-(

2

1 Answer 1

1

Normally, on OSX, the java command should follow JAVA_HOME unless somehow other java takes precedence.

You can use which java to show where actually the java you call according to your $PATH.

➜ which java
/usr/bin/java

➜ ls -la /usr/bin/java
lrwxr-xr-x  1 root  wheel  74 Jun 10 14:33 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

You can see in my machine /usr/bin/java actually symlink to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java which is a kind of proxy to call the right java according to $JAVA_HOME

So, my suggestion is sorting out your $PATH to call /usr/bin first. Or just set export PATH=/usr/bin:$PATH to put /usr/bin in the front.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.