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).
Best Answer
Recommended commands to install OpenJDK 11 from AdoptOpenJDK (with notes after the
#
sign):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 meopenjdk version "11.0.3"
andjavac --version
shows mejavac 11.0.3
(with noJAVA_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:
Alternative installation of OpenJDK from
download.oracle.com
- with no AdoptOpenJDK tap needed:To install OpenJDK 11 from
download.oracle.com
:To install most recent OpenJDK version from
download.oracle.com
:Here is the source of the
java
cask: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rbTo 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 asjava8
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