Homebrew is a package manager that makes it easy for us to install all sorts of development tools such as MySQL, Mongo, Ruby on Rails, and Java. Below are the steps required to install Java using Homebrew.

Step 0 - Install Homebrew

Homebrew does not come pre-installed with Mac, so you'll have to install it yourself. Thankfully, it's a single line of code that you paste into the terminal. Here are instructions on how to install Homebrew on Mac.

Approach #1 - Install Up-To-Date JDK

brew cask installs macOS apps, fonts and plugins, and other non-open source software including Java. You don't need to install cask, but you will need to reference it.

brew cask install java

Approach #2 - Install Older JDK

Some projects might still depend on an older JDK (such as Java 8), and in these situations, the best thing to do is install AdoptOpenJDK.

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8

Step 3 - Verify Your Work

brew cask info java


If brew keeps erroring out for no reason, I suggest running this command.

brew cleanup && brew cask cleanup