How can I upgrade my mac to OpenJDK 11 using Homebrew?
If I would have an older version of Java JDK on my mac such as Java SE 8 or OpenJDK 8, what would be a quick way to upgrade to OpenJDK 11 using Homebrew (using the brew
command)?
Motivation for using Homebrew: Homebrew provides an easy way to do reproducible installation of a number of system tools (and makes it easier to undo mistakes).
Recommended commands to install OpenJDK 11 from AdoptOpenJDK (with notes after the #
sign):
brew tap adoptopenjdk/openjdk # assuming this tap was not already added
brew cask install adoptopenjdk11 # this command *may* need a password to succeed
Note that OpenJDK as used by AdoptOpenJDK is open source under GPL v2 license with a Classpath exception.
This answer assumes that a recent version of Homebrew is installed, with brew cask install
enabled and working.
At this point, assuming that no newer version of Java or Java JDK is installed, java -version
shows me openjdk version "11.0.3"
and javac --version
shows me javac 11.0.3
(with no JAVA_HOME
environment variable in use). The following commands show both JDK versions installed:
/usr/libexec/java_home -V
ls /Library/Java/JavaVirtualMachines
To install latest version of OpenJDK from AdoptOpenJDK:
brew tap adoptopenjdk/openjdk # (if not already added)
brew cask install adoptopenjdk # (*may* need a password to succeed)
Alternative installation of OpenJDK from download.oracle.com
- with no AdoptOpenJDK tap needed:
To install OpenJDK 11 from download.oracle.com
:
brew cask install java11 # (*may* need a password to succeed)
To install most recent OpenJDK version from download.oracle.com
:
brew cask install java # (*may* need a password to succeed)
Here is the source of the java
cask: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb
To find related packages on Homebrew:
-
brew search jdk
(shows both AdoptOpenJDK and the Oracle JDK) -
brew search java
(see notes below)
According to this article, newer versions of Java JDK from Oracle are under GPL v2 license with a Classpath exception (they seemed to link to the same page on the non-https
site).
Note that some previous java
packages such as java8
are still using Oracle JDK instead of OpenJDK. How to install and verify an older OpenJDK version using AdoptOpenJDK is described in: How can I install java openjdk 8 on High Sierra
If for any reason you want an installation not depending on a package manager (frequently happening if you need to use several versions as a developer) you can download the appropriate zip file from https://www.azul.com/downloads/zulu/zulu-mac/. Unzip it and add the bin
directory to your $PATH
if needed.
As of 2019-02-21 Java 7, 8 and 11 are available as latest releases.