Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save productinfo/ac0af7e776cd40aa7dbf62e08af807e3 to your computer and use it in GitHub Desktop.
Save productinfo/ac0af7e776cd40aa7dbf62e08af807e3 to your computer and use it in GitHub Desktop.
How to install different Java Versions with Homebrew on MacOS

We will install OpenJDK for anything Java 8 and later. Anything prior is probably Oracle JDK.

Prerequisite: Install Homebrew.

Remember to update your formulas.

$ brew update

Latest OpenJDK Feature Release (Java 12, 13, 14, etc...)

  • Note that this formula is available on homebrew/core, so you don't need to have tapped any caskrooms.
$ brew info java        # Confirm information about the formula. Note that it's poured from the OpenJDK formula.
$ brew install java     # Install the most recent feature release of OpenJDK

OpenJDK 11

  • At time of writing, there is no such thing as a java-lts formula or cask. You must explicitly choose to install Java 11.
  • Note that this formula is available on homebrew/core, so you don't need to have tapped any caskrooms.
$ brew info java11      # Confirm information about the formula. Note that it's poured from the OpenJDK formula.
$ brew install java11   # Install OpenJDK 11

AdoptOpenJDK 8

$ brew tap homebrew/cask-versions   # Tap the cask-versions taproom to get access to different cask versions.
$ brew search jdk                   # Find `adoptopenjdk8` in the casks
$ brew caskinfo adoptopenjdk8       # Confirm information about the cask. Note that this is an AdoptOpenJDK build of OpenJDK.
$ brew cask install adoptopenjdk8   # Install the AdoptOpenJDK build of OpenJDK8

See the AdoptOpenJDK HomeBrew Tap Github Repo for an alternative taproom with more AdoptOpenJDK versions.

Java 7

  • OBSOLETE: It appears Java 7 is no longer available in homebrew/cask-versions. It used to be available at caskroom/versions/java7.
# THIS IS OBSOLETE. INCLUDED FOR REFERENCE PURPOSES.
$ brew cask info caskroom/versions/java7 # Query info about Java cask installation beforehand
$ brew cask install caskroom/versions/java7 # For Java 7

If you know how to find Java 7 on Homebrew, please leave a comment on how to do so and we can add it in here.

Java 6

$ brew tap homebrew/cask-versions
$ brew cask install java6

Notes

  • MacOS Java install location will be at /Library/Java/JavaVirtualMachines/.
  • When upgrading Java installations with Homebrew
    • Be aware upgrades will overwrite the cacerts truststore file (if you have edited that)
    • Be aware that the JDK install directory's name may fall out of date when you perform the upgrade. You may have to manually rename the directory, and make tweaks to your configurations accordingly.
  • I recommend jEnv for switching between multiple Java environments on MacOS.
  • I think it's generally wise to have homebrew/cask and homebrew/cask-versions tapped. They are practically core.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment