How to use Mac's java_home to pick between the same version of AdoptOpenJDK and AzulOpenJDK?

3k views Asked by At

I have in my .zshrc the following line which pick which JAVA_HOME it is

export JAVA_HOME=$(/usr/libexec/java_home -v '1.8*')

I used to only have AdoptOpenJdk, hence doing that can let me easily pick AdoptOpenJdk version 1.8

However, after installing Zulu, when I run java_home -V, I have the below

./java_home -V             
Matching Java Virtual Machines (2):
    1.8.0_282 (arm64) "Azul Systems, Inc." - "Zulu 8.52.0.23" /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
    1.8.0_282 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

After that, now my JAVA_HOME which is running /usr/libexec/java_home -v '1.8*' to determined is pointing to Zulu open jdk.

How can I get it back to AdoptJDK by just using java_home command?

2

There are 2 answers

0
MaTriXy On

Try using

'unset JAVA_HOME;export JAVA_HOME=$(/usr/libexec/java_home -v '1.8*')'
0
Nick On

I've used free this tool in the past, it allows you to switch between different Java environments. https://www.jenv.be/