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
brew search java
to find the answer?brew search
? What if the next user never though of usingbrew search
?man brew
or the website probably isn't asking too much, me thinks.brew search
, in response to the comments so far, along with important information about some older Homebrewjava
packages.brew
would likely help a lot of people even if it’s not what OP had in mind. I’m a fan of several answers to solve the general problem and OP can always “check” the one that fits best - even changing that over time if they choose so.