Skip to content

Instantly share code, notes, and snippets.

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 steevehook/3edd74ffa1181d4fb2db47bbdfbf23a9 to your computer and use it in GitHub Desktop.
Save steevehook/3edd74ffa1181d4fb2db47bbdfbf23a9 to your computer and use it in GitHub Desktop.
MacOS JDK installation

After Sierra upgrade, all my JDK were removed. So here is how I reinstalled all of them with only brew commands, and manage them with jEnv.

First do all your mac updates (especially XCode), then:

Install Brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install JDK 8:

brew cask install java

Install other JDKs:

brew tap caskroom/versions
brew search java
brew cask install java7
brew cask install java6
brew cask install java9-beta

Upgrading

brew update
brew upgrade

Managing your JDKs globally, per shell or per folder with Jenv:

Website: http://www.jenv.be/

brew install jenv

Since I have zsh (see website for bash instructions), I also execute:

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc

Source your profile again:

. ~/.zshrc

(for bash, you have to do the equivalent, )

. ~/.bash_profile

Then add your JDKs:

jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/
...

Then switch between them:

List managed JDKs

jenv versions

outputs:

  system
  1.6
  1.6.0.65
  1.7
  1.7.0.79
  1.7.0.80
* 1.8 (set by /Users/matc/.jenv/version)
  1.8.0.112
  9-ea
  oracle64-1.6.0.65
  oracle64-1.7.0.79
  oracle64-1.7.0.80
  oracle64-1.8.0.112
  oracle64-9-ea

Configure global version

jenv global 1.8

Configure local version (per directory)

jenv local 1.6

Configure shell instance version

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