Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JDK version switch on MacOS
1. Check the current version out of curiosity
> /usr/libexec/java_home -V
Expected result should be similar to
Matching Java Virtual Machines (2):
9.0.4, x86_64: "Java SE 9.0.4" /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
1.8.0_162, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
2. Update your .bash_profile with shortcuts to swith between versions easily:
from whenever you are, go to you home dir
> cd
> vi .bash_profile
add lines like:
alias j9="export JAVA_HOME=`/usr/libexec/java_home -v 9`; java -version"
alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version"
save and exit (in vi it's `:wq`)
update your bash_profile with
> source .bash_profile
3. You are ready to go.
courtesy of
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.