2

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).

  • 1
    Is there a specific reason you can't simply run brew search java to find the answer? – nohillside Jan 23 at 19:07
  • What if I never though of using brew search? What if the next user never though of using brew search? – brodybits Jan 23 at 19:09
  • 2
    Well, having a look at man brew or the website probably isn't asking too much, me thinks. – nohillside Jan 23 at 19:13
  • Nor is posing a question along with the answer in order to help the next user, which is exactly what I did. I updated the answer with some information about how a user could use brew search, in response to the comments so far, along with important information about some older Homebrew java packages. – brodybits Jan 23 at 19:24
  • An answer showing how to use 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. – bmike May 20 at 23:59
2

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

  • Be aware that Oracle has recently changed the license terms for their Java distribution, Oracle JDK. That product cannot be used in production free-of-cost. It may be used only for “developing, testing, prototyping and demonstrating Your Application”. For more info about several other sources for Java, see my Question, Obtain Java 11 for macOS?. Most of those sources also provide Java 8. – Basil Bourque Mar 3 at 5:45
  • @BasilBourque recent versions of the Homebrew java cask will use OpenJDK, which is open source under GPL v2 license with a Classpath exception. I just added a note to the answer to make this clear. For some older versions such as Java 8 I would suggest using the AdoptOpenJDK cask as I described in this answer. I generally like to use Homebrew to make it easier to undo and redo package installations as needed, that is why I stated using Homebrew in my question. – brodybits Mar 4 at 15:47
  • I just updated this answer to recommend using AdoptOpenJDK, and to recommend using a specific version as needed to use OpenJDK as specified in the original question. – brodybits May 21 at 1:48
1

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.

  • The original question specifically stated "using Homebrew" in both the title and body. The reason is that I would personally rather use Homebrew than do the manual installation. I do think the information in this answer could help some some others and should be given for a different question. (Feel free to do your own question-and-answer if appropriate, like I did for this question.) – brodybits May 20 at 23:25
  • @brodybits please try to extend the courtesy of everyone to put up answers on any post - even wrong answers aren’t deleted here - and this looks like a genuine attempt to help people that may be looking to your question to learn. A constructive comment is fine, but answers that change the scope can be highly useful. Many people don’t need to “use homebrew” so +1 to this in my book. – bmike May 20 at 23:57
  • What should I do to "extend the courtesy"? And how should I deal with "answers that change the scope", which I did already say "could help some others"? Does that mean I should have said nothing, update the original question to adapt to the expanded scope, add a note to my answer, or anything else? (I would favor updating the question to allow an alternative to the scope, if we want to encourage an answer that ventures outside the scope. And I certainly do not favor just deleting answers that are not 100% correct.) And does anyone else have any ideas of what I should do? – brodybits May 21 at 0:08
  • @brodybits I think you should add the reason to use Homebrew (which I think is a bad idea and I think you will too in time) to your question instead of having it in a comment to an answer you do not like. – Thorbjørn Ravn Andersen May 21 at 9:04
  • I just added my motivation for using Homebrew to the body of the question. If you think it is "a bad idea" and think I "will too in time", can you explain the the reasoning? – brodybits May 21 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .