I want to install OpenJDK Java 11 on Mac OSX and have it work alongside other JDK's since it is a newer release. Currently, I downloaded the tar.gz and placed it in my path but that is hard to maintain.
The only other installs I found that do more things automatically are the Oracle install via Homebrew cask, but that is the commercial JDK and I want the open-source one!
brew cask info java
java: 11,28:55eed80b163941c8885ad9298e6d786a https://www.oracle.com/technetwork/java/javase/overview/index.html
Which it is the Oracle JDK and not OpenJDK, see: https://discourse.brew.sh/t/how-to-install-openjdk-with-brew/712
Following directions from an older question (Mac OS X and multiple Java versions) is outdated and gives me the wrong version -- Oracle not OpenJDK.
Note: this question is intentionally written and answered by the author (Self-Answered Questions), so that the idiomatic answers to commonly asked topics are present in SO.
note: These solutions work for your specific case of Java 11 OpenJDK but also work for any other previous Java version covered by the listed version managers. This includes alternative JDK's from OpenJDK, Oracle, IBM, Azul, Graal and more. Easily work with Java 7, Java 8, Java 9, Java 10, and now 11.
First, install Java using whatever method you prefer including Homebrew, SDKMAN or a manual install of the tar.gz file. The advantages of a manual install is that the location of the JDK can be placed in a standardized location for Mac OSX.
Install with SDKMAN
This is a simple model in that it handles both installation and version switching, with a caveat that it installs the JDK into a non-standard directory.
<see below "Installing and Switching versions with SDKMAN">
Install using Jabba
This is also a simple model in that both installation and version switching are handled by the same tool. The installations are made to a non-standard directory.
<see below "Installing and Switching versions with Jabba">
Install manually from OpenJDK download page:
Download OpenJDK 11 for Mac OSX from http://jdk.java.net/11/
Unarchive the OpenJDK tar, and place the resulting
jdk-11.jdkfolder into your
/Library/Java/JavaVirtualMachines/folder since this is the standard and expected location of JDK installs. You can also install anywhere you want in reality.
Install with Homebrew
For other versions of Java:
install Homebrew if you haven't already.
Add the casks tap:
brew tap homebrew/cask-versions
Look for installable versions:
brew search java
Check the details on the version that will be installed:
brew cask info java
Note that the current release is the Oracle commercial version of Java 11, and not OpenJDK 11.
Install a specific version of the JDK such as
javafor the current:
brew cask install java
And these will be installed into
/Library/Java/JavaVirtualMachines/ which is the traditional location expected on Mac OSX.
Other installation options:
Zulu® is a certified build of OpenJDK that is fully compliant with the Java SE standard. Zulu is 100% open source and freely downloadable. Now Java developers, system administrators, and end users can enjoy the full benefits of open source Java with deployment flexibility and control over upgrade timing.
Where is my JDK?!?!
To find locations of previously installed Java JDK's installed at the default system locations, use:
This is useful when using tools like JEnv, or adding a local install to SDKMAN, or linking a system JDK in Jabba -- and you need to know where to find them.
If you need to find JDK's instaled by other tools, check these locations:
- SDKMAN installs to
- Jabba installs to
Switching versions with JEnv
JEnv expects the Java JDK's to already exist on the machine and can be in any location. Typically you will find installed Java JDK's in
/Library/Java/JavaVirtualMachines/. JEnv allows setting the global version of Java, one for the current shell, and a per-directory local version which is handy when some projects require different versions than others.
Install JEnv if you haven't already, instructions on the site http://www.jenv.be/ for manual install or using Homebrew.
Add any Java version to JEnv (adjust the directory if you placed this elsewhere):
jenv add /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
Set your global version using this command:
jenv global 11
You can also add other existing versions using
jenv add in a similar manner, and list those that are available. For example Java 8:
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home jenv versions
See the JEnv docs for more commands. You may now switch between any Java versions (Oracle, OpenJDK, other) at any time either for the whole system, for shells, or per local directory.
To help manage
JAVA_HOME while using JEnv you can add the export plugin to do this for you.
$ jenv enable-plugin export You may restart your session to activate jenv export plugin echo export plugin activated
The export plugin may not adjust
JAVA_HOME if it is already set, so you may need to clear this variable in your profile so that it can be managed by JEnv.
You can also use
jenv exec <command> <parms...> to run single commands with
PATH set correctly for that one command, which could include opening another shell.
Installing and Switching versions with SDKMAN
SDKMAN is a bit different and handles both the install and the switching. SDKMAN also places the installed JDK's into its own directory tree, which is typically
~/.sdkman/candidates/java. SDKMAN allows setting a global default version, and a version specific to the current shell.
Install SDKMAN from https://sdkman.io/install
Install Java 11 using SDKMAN:
sdk install java 11.0.0-open
Make 11 the default version:
sdk default java 11.0.0-open
Or switch to 11 for the session:
sdk use java 11.0.0-open
You can list available versions for installation using the list command:
sdk list java
And install additional versions, such as JDK 8:
sdk install java 8.0.181-oracle
SDKMAN can work with previously installed existing versions. Just do a local install giving your own version label and the location of the JDK:
sdk install java my-local-11 /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
And use it freely:
sdk use java my-local-11
SDKMAN will automatically manage your
JAVA_HOME for you as you change versions.
Installing and Switching versions with Jabba
Jabba also handles both the install and the switching. Jabba also places the installed JDK's into its own directory tree, which is typically
Install Jabba by following the instructions on the home page.
List available JDK's
Install Java JDK 11
jabba install firstname.lastname@example.org
jabba use email@example.com
You can also alias version names, link to existing JDK's already installed, and find a mix of interesting JDK's such as GraalVM, Adopt JDK, IBM JDK, and more. The complete usage guide is available on the home page as well.
Jabba will automatically manage your
JAVA_HOME for you as you change versions.