Skip to content

Instantly share code, notes, and snippets.

@gembin
Last active April 8, 2018 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gembin/c14f413554313de24c0b850fc035cb60 to your computer and use it in GitHub Desktop.
Save gembin/c14f413554313de24c0b850fc035cb60 to your computer and use it in GitHub Desktop.
Switching JDK on Mac OS X

/usr/libexec/java_home -V command to get the list of installed JDKs.

For example:

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_161, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

Add the following aliases in ~/.bash_profile

alias jdk7='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)'
alias jdk8='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)'
alias jdk9='export JAVA_HOME=$(/usr/libexec/java_home -v 9)'

Or use http://sdkman.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment