Skip to content

Instantly share code, notes, and snippets.

@ozooxo ozooxo/jdk.md
Last active May 8, 2018

Embed
What would you like to do?
Multiple JDK on MacOS

Search Java version and install:

$ brew tap caskroom/versions

$ brew cask search java
==> Exact Match
java ✔
==> Partial Matches
charles-applejava          eclipse-javascript         java6                     netbeans-java-ee           yourkit-java-profiler
eclipse-java               java-jdk-javadoc           java8                     netbeans-java-se

$ brew cask install java6
$ brew cask install java8

Check existing JDK:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    10, x86_64:	"Java SE 10"	/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home
    1.8.0_172, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
    1.6.0_65-b14-468, x86_64:	"Java SE 6"	/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386:	"Java SE 6"	/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home

Switch JDK version may be done through jenv. See this link for detail.

Right now, I have

/Library/Java $ ls -la
total 0
drwxr-xr-x   6 root  wheel   192 Apr 20 09:47 .
drwxr-xr-x+ 66 root  wheel  2112 Apr  6 11:57 ..
drwxr-xr-x   2 root  wheel    64 Jul 15  2017 Extensions
lrwxr-xr-x   1 root  wheel    64 Apr 20 09:47 Home -> /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
drwxr-xr-x   5 root  wheel   160 Apr 20 09:47 JavaVirtualMachines
lrwxr-xr-x   1 root  wheel    59 Apr  4 16:26 MacOS -> /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/MacOS

So, export JAVA_HOME=/Library/Java/Home will then send to Java 8, alghouth with a lack of definition it is Java 10 (which is at /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home rather than /Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/MacOS).

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.