Create a gist now

Instantly share code, notes, and snippets.

Embed
macOS: Manage Multiple versions of Java

macOS: Manage Multiple versions of Java

Setup tooling

brew update
brew install jenv
brew tap caskroom/cask
brew tap caskroom/versions
mkdir ~/.jenv/versions

# Already in: https://github.com/branneman/dotfiles/blob/f2002f4/.profile#L41-L42
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.profile
echo 'eval "$(jenv init -)"' >> ~/.profile

Restart your terminal when you're done.

Install Java versions

Download & Install all the different Java versions you like, then print all found Java versions:

/usr/libexec/java_home -V

Add them to jenv:

jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

Print all installed versions

jenv versions

Switch version

jenv global oracle64-1.8.0.144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment