Turns out java has been moved into brew core recently, so the correct command as of August 2022 is:

brew install java

Then check your installation by running

java -version

If the result does not looks like this:

openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)

but like this:

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Then you also need to create a symlink for the system Java wrappers to find this JDK:

sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
     /Library/Java/JavaVirtualMachines/openjdk.jdk
Answer from Tim Fulmer on Stack Overflow

Turns out java has been moved into brew core recently, so the correct command as of August 2022 is:

brew install java

Then check your installation by running

java -version

If the result does not looks like this:

openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)

but like this:

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Then you also need to create a symlink for the system Java wrappers to find this JDK:

sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
     /Library/Java/JavaVirtualMachines/openjdk.jdk
Answer from Tim Fulmer on Stack Overflow
🌐
Homebrew
formulae.brew.sh › formula › openjdk
Homebrew Formulae: openjdk
brew install openjdk · Also known as: java, openjdk@26 · Development kit for the Java programming language · https://openjdk.org/ License: GPL-2.0-only WITH Classpath-exception-2.0 · Development: Pull requests · Formula JSON API: /api/formula/openjdk.json ·
🌐
DevQA
devqa.io › brew-install-java
How to Use Brew to Install Java on Mac
If not, you can install it via: $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" If you already have brew installed, make sure you have the latest version by running the following command in a terminal
🌐
Mr N
bigsoft.co.uk › blog › 2025 › 11 › 07 › installing-all-the-javas-on-a-mac-and-switching-between-them
Installing all the Javas on a Mac and switching between them
November 7, 2025 - brew install openjdk@8 brew install openjdk@11 brew install openjdk@17 brew install openjdk@21 brew install openjdk@25 ... After the install has completed add this to your ~/.bash_profile and restart the shell. export PATH="$HOME/.jenv/bin:$PATH" eval "$(jenv init -)" If you'd like JAVA_HOME ...
🌐
GitHub
github.com › jbranchaud › til › blob › master › java › install-java-on-mac-with-brew.md
til/java/install-java-on-mac-with-brew.md at master · jbranchaud/til
$ brew info openjdk ... For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk ...
Author   jbranchaud
🌐
GitHub
github.com › AdoptOpenJDK › homebrew-openjdk
GitHub - AdoptOpenJDK/homebrew-openjdk: AdoptOpenJDK HomeBrew Tap · GitHub
June 17, 2024 - $ brew tap AdoptOpenJDK/openjdk $ brew install --cask <version>
Starred by 1.8K users
Forked by 97 users
Languages   Ruby 87.6% | Shell 12.4%
Find elsewhere
🌐
Medium
medium.com › @haroldfinch01 › step-by-step-guide-installing-and-switching-java-versions-on-mac-osx-f3896b9872f4
Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX | by Harold Finch | Medium
May 21, 2024 - Install Java 8 · brew install openjdk@8 · Install Java 11 · brew install openjdk@11 · Install Java 17 · brew install openjdk@17 · After installing each version, follow the instructions provided by Homebrew to add the Java versions to your PATH. jenv is a Java environment manager that makes it easy to switch between different versions of Java.
🌐
Mac Install Guide
mac.install.guide › java › brew-cask
Brew Install Java - Easy Cask Method · 2026
Brew install Java on Mac. One command to install the recommended Temurin JDK. The cask method without PATH or symlink configuration. How to fix common Homebrew Java issues.
🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
Note that it's poured from the OpenJDK formula. $ brew install openjdk@11 # Install OpenJDK 11 · Homebrew does not offer an obvious way to install an older feature release of Java other than the current generally-available feature release.
🌐
Homebrew
formulae.brew.sh › cask › oracle-jdk
Homebrew Formulae: oracle-jdk
brew install --cask oracle-jdk · Name: Oracle Java Standard Edition Development Kit · JDK from Oracle · https://www.oracle.com/java/technologies/downloads/ Development: Pull requests · Cask JSON API: /api/cask/oracle-jdk.json · Cask code: ...
🌐
Andrew Hoog
andrewhoog.com › posts › 3-ways-to-install-java-on-macos-2023
3 ways to install Java on macOS [2023] - Don't Panic
January 12, 2023 - >> /Users/hiro/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/hiro/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" - Run brew help to get started - Further documentation: https://docs.brew.sh · The first commands initialize your shell environment and then you do a one-time setup of your current shell (you could also restart your terminal to execute .zprofile). From there, you can install java with this one command:
🌐
Codemia
codemia.io › home › knowledge hub › how to brew install java?
How to brew install java? | Codemia
January 27, 2025 - Update Homebrew: It is a good practice to update Homebrew before installing any packages to ensure you’re installing the latest versions. ... Search for Java Versions: To see the versions of Java that are available for installation, use the command:
🌐
Oracle
docs.oracle.com › en › java › javase › 23 › install › installation-jdk-macos.html
4 Installation of the JDK on macOS - Java
January 22, 2025 - For example, JDK 23.0.1 is installed in /Library/Java/JavaVirtualMachines/jdk-23.jdk.
🌐
Mkyong
mkyong.com › home › java › how to install java jdk on macos
How to install Java JDK on macOS - Mkyong.com
January 19, 2021 - This article shows how to install Java JDK on macOS, Homebrew package manager, manual installation, and switch between different JDK versions.
🌐
Medium
medium.com › @manvendrapsingh › installing-many-jdk-versions-on-macos-dfc177bc8c2b
Installing & switching between multiple JDK on macOS | by Manvendra P Singh | Medium
February 20, 2023 - After this completes, we can use homebrew to install available formulae or cask with just one line commands brew install xxxx or brew install --cask xxxx · First, let's search Homebrew to find available java versions.
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-java-on-macos
How to Install Java on MacOS: A Step-by-Step JDK Installation - GeeksforGeeks
July 23, 2025 - brew install openjdk@23 · To make JDK 23 the default version, add its path to your shell profile: Find the installation path: /usr/libexec/java_home -v 23 ·
🌐
Tim Santeford
timsanteford.com › posts › how-to-install-java-on-macos-using-homebrew
How to Install Java on MacOS Using Homebrew - Tim Santeford
Let me take you through the steps to get Java installed on your machine. First, open your terminal and run the following command to install the latest version of OpenJDK:[amazon_auto_links id="793"] ... sudo ln -sfn $(brew --prefix openjdk)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
🌐
freeCodeCamp
freecodecamp.org › news › how-to-install-java-on-mac
How to Install Java on Mac in 2026
February 20, 2026 - See Install Java on Mac for detailed instructions. Homebrew formula. The command brew install openjdk@25 installs a Homebrew-managed build. This approach requires manual symlink configuration before macOS can discover it.