Manually downloading, extracting and configuring the installation of OpenJDK 11+ is a high-maintenance exercise. Particularly if you need to install and switch between multiple versions of the JDK.
The following options for installing OpenJDK 11+ and switching between versions make the job easier..
Jabba is a Java version manager inspired by nvm (Node.js) written in Go.
- Install Jabba if you don't have it already
curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh
- The list of available JDK can be displayed
jabba ls-remote
1.11.0
1.10.0
1.10.0-2
1.8.181
1.6.65
[email protected]
[email protected]
....
- OpenJDK 11 can be installed with
jabba install [email protected]
- Switch to a specific version with
jabba use [email protected]
Jabba automatically manages JAVA_HOME
and PATH
settings. It installs JDKs to ~/.jabba/jdk
.
SDKMAN is a tool for running multiple development kits on a machine. It can manage the installation and switching of Java versions.
- Install SDKMAN if you don't have it already
url -s "https://get.sdkman.io" | bash
Follow the instructions on-screen.
Next, run the following
source "$HOME/.sdkman/bin/sdkman-init.sh"
- The different available versions of Java can be listed
sdk list java
- Install the OpenJDK 11 with
sdk install java 11.0.0-open
- Make OpenJDK 11 the default version
sdk default java 11.0.0-open
or switch to a different version for a particular session
sdk use java 11.0.0-open
Before 3rd October 2018 the Oracle Java JDK was available via Homebrew. It has now been updated to OpenJDK.
- Install Homebrew if you don't have it already. Ensure it is updated
brew update
- Add the casks tap
brew tap homebrew/cask-versions
- Search for installable versions
brew search java
- Verify the details of the version that will be installed
brew cask info java
- Install a specific version
java8
,java10
or the latestjava
brew cask install java
The AdoptOpenJDK is also available from Homebrew Cask
brew cask install adoptopenjdk
The installation directory is /Library/Java/JavaVirtualMachines/
which is the traditional location on MacOSX
To find the locations of installed JDKs
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
11, x86_64: "OpenJDK 11" /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
1.8.0_45, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
or for a specific version
/usr/libexec/java_home -v 11
/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
Note the upper and lowercase 'v'.
The /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home
utility can be to change versions
manually or add aliases for a particular shell. The following can be added to .bash_profile
or .profile
export JAVA8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA9_HOME=$(/usr/libexec/java_home -v9)
export JAVA10_HOME=$(/usr/libexec/java_home -v10)
export JAVA11_HOME=$(/usr/libexec/java_home -v11)
alias java8='export JAVA_HOME=$JAVA8_HOME'
alias java9='export JAVA_HOME=$JAVA9_HOME'
alias java10='export JAVA_HOME=$JAVA10_HOME'
alias java11='export JAVA_HOME=$JAVA11_HOME'
# Specify Java 11 as the default version
java11
The aliases can be used to change versions on the fly
java8
The Java version can be checked with
java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)