Oracle recently invested work into making OpenJDK compatible with their commercial JDK. It is now worth using OpenJDK as an open source runtime for development and production environments.
Download the macOS / x64 build from https://jdk.java.net/12/. It should download into your
Unzip the Package
Depending on your browser settings the downloaded package may already be unzipped. If not just double click the file in Finder and it will decompress the package contents as a directory.
Copy the unzipped directory
Notice that JDK 11 is there too. I can switch between these versions. More on switching versions later.
Next make sure the environment is configured. To be most compatible for all kinds of UNIX behavior on macOS I consolidate shell configuration to the
.bashrc file and source it from the
.bash_profile file to source the
.bashrc file in your home directory.
~$ cat .bash_profile
if [ -f ~/.bashrc ]; then
Set the environment variable
JAVA_HOME in the
.bashrc file. Also include
JAVA_HOME in the
PATH environment variable.
~$ cat .bashrc
Restart your shell and run
java -version to see what version is loading.
$ java -version
openjdk version "12" 2019-03-19
OpenJDK Runtime Environment (build 12+33)
OpenJDK 64-Bit Server VM (build 12+33, mixed mode, sharing)
Switching JDK versions is simple. Set the
-v flag in the
JAVA_HOME environment variable in the
.bashrc file and restart your shell.
For Java 11
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
For Java 12
By default the latest is used so specifying the latest version with the
-v flag is optional.
export JAVA_HOME=$(/usr/libexec/java_home -v 12)
View Installed Versions
Run the following to see which versions of the JDK are installed. Running the command shows what JDK versions are installed and where.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
12, x86_64: "OpenJDK 12" /Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home
11.0.2, x86_64: "OpenJDK 11.0.2" /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home