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
- 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
- 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
$ 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.
- OBSOLETE: It appears Java 7 is no longer available in
homebrew/cask-versions
. It used to be available atcaskroom/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.
$ brew tap homebrew/cask-versions
$ brew cask install java6
- 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.
- Be aware upgrades will overwrite the
- I recommend jEnv for switching between multiple Java environments on MacOS.
- I think it's generally wise to have
homebrew/cask
andhomebrew/cask-versions
tapped. They are practically core.