Skip to content

Instantly share code, notes, and snippets.

@mathieucarbou
Last active April 28, 2022 20:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save mathieucarbou/364540c4f03e166c2c01eb94d22c5eca to your computer and use it in GitHub Desktop.
Save mathieucarbou/364540c4f03e166c2c01eb94d22c5eca 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
@mathieucarbou
Copy link
Author

jEnv also makes sure all the JDK binaries are linked (schims mechanism like brew or scoop).

It means that you do not need to find the binary for Java Mission Control on MacOS anymore! Just run: jmc

➜  ehcache3 git:(issue-1574) ✗ which jmc
/Users/matc/.jenv/shims/jmc
➜  ehcache3 git:(issue-1574) ✗ ls ~/.jenv/shims 
ControlPanel   idlj           javac          javap          jconsole       jdeps          jinfo          jmc            jsadebugd      jstatd         native2ascii   rmic           serialver      wsgen
appletviewer   jar            javadoc        javapackager   jcontrol       jhat           jjs            jmod           jshell         jvisualvm      orbd           rmid           servertool     wsimport
apt            jarsigner      javafxpackager javaws         jdb            jhsdb          jlink          jps            jstack         jweblauncher   pack200        rmiregistry    tnameserv      xjc
extcheck       java           javah          jcmd           jdeprscan      jimage         jmap           jrunscript     jstat          keytool        policytool     schemagen      unpack200

@mohataher
Copy link

brew cask install java

Installs Java 9 now. Please update your gist.

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