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@21
Homebrew Formulae: openjdk@21
brew install openjdk@21 · 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@21.json · Formula code: openjdk@21.rb on GitHub ·
🌐
Homebrew
formulae.brew.sh › formula › openjdk
Homebrew Formulae: 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 · Formula code: openjdk.rb on GitHub ·
🌐
Mac Install Guide
mac.install.guide › java › java-21
Install Java 21 on Mac · Mac Install Guide · 2026
Homebrew is the easiest way to install Java 21. It handles architecture detection, installs to the correct location, and registers Java with macOS automatically.
🌐
Homebrew
formulae.brew.sh › cask › oracle-jdk@21
Homebrew Formulae: oracle-jdk@21
brew install --cask oracle-jdk@21 · 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@21.json · Cask ...
🌐
Medium
ymkfelix.medium.com › how-to-set-up-multiple-java-versions-on-a-macbook-8bae41345f72
How to set up multiple Java versions on a MacBook? | by Ye Min Ko | Medium
August 13, 2024 - sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk sudo ln -sfn /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk
🌐
Homebrew
formulae.brew.sh › cask › graalvm-jdk@21
Homebrew Formulae: graalvm-jdk@21
brew install --cask graalvm-jdk@21 · Name: GraalVM Java Development Kit · GraalVM from Oracle · https://www.graalvm.org/ Development: Pull requests · Cask JSON API: /api/cask/graalvm-jdk@21.json · Cask code: graalvm-jdk@21.rb on GitHub · Current version: 21.0.11,9 ·
Find elsewhere
🌐
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 - $ jenv global 21 $ echo $JAVA_HOME /Users/mrn/.jenv/versions/21 $ java -version openjdk version "21.0.9" 2025-10-21 OpenJDK Runtime Environment Homebrew (build 21.0.9) OpenJDK 64-Bit Server VM Homebrew (build 21.0.9, mixed mode, sharing)
🌐
Homebrew
formulae.brew.sh › cask › temurin@21
Homebrew Formulae: temurin@21
Name: Eclipse Temurin 21 · JDK from the Eclipse Foundation (Adoptium)
🌐
Medium
medium.com › @karrasrisushma › java-21-learning-journey-draft-895c8b80f375
Java 21 - Unnamed Classes and Instance Main Method
April 9, 2025 - Java 21 for exploring the latest features. Switching versions manually is tedious and error-prone. jenv makes it seamless and reproducible. jenv add /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home
🌐
Medium
medium.com › neural-engineer › installing-the-jdk-on-macos-2025-with-homebrew-temurin-and-openjdk-708f66701cdc
Installing the JDK on macOS (2025) with Homebrew, Temurin, and OpenJDK | by PI | Neural Engineer
December 1, 2025 - sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \ /Library/Java/JavaVirtualMachines/openjdk.jdk · For Temurin casks that skipped creating a JVM entry: sudo ln -sfn /Library/Java/JavaVirtualMachines/temurin-*/Contents/Home \ /Library/Java/JavaVirtualMachines/temurin.jdk · java -version · You should see something like: openjdk version "21.0.1" 2025-01-01 LTS ·
🌐
Homebrew
formulae.brew.sh › cask › semeru-jdk-open@21
Homebrew Formulae: semeru-jdk-open@21
Name: IBM Semeru Runtime (JDK 21) Open Edition · Production-ready JDK with the OpenJDK class libraries and the Eclipse OpenJ9 JVM
🌐
Homebrew
formulae.brew.sh › cask › zulu@21
Homebrew Formulae: zulu@21
brew install --cask zulu@21 · Name: Azul Zulu Java Standard Edition Development Kit · OpenJDK distribution from Azul · https://www.azul.com/downloads/ Development: Pull requests · Cask JSON API: /api/cask/zulu@21.json · Cask code: zulu@21.rb ...
🌐
Uga
cobweb.cs.uga.edu › ~maria › classes › 2720-2025-Spring › Wk01-setup-brew.html
Installing JDK 21 on macOS and Windows
Update Homebrew (if already installed): brew update # brew doctor # run diagnostics brew upgrade # upgrade packages · Install JDK 21: brew install openjdk@21 · Verify Installation: java -version · Optional: Manage Multiple Java Versions (if needed): brew install jenv ·
🌐
GitHub
gist.github.com › gwpantazes › 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew · GitHub
There is a java11 alias which points to openjdk@11. $ brew info openjdk@11 # Confirm information about the formula. 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.
🌐
javaspring
javaspring.net › blog › brew-install-java-21
Unleashing the Power of Java 21 with Brew: A Comprehensive Guide — javaspring.net
This command tells Homebrew to fetch the OpenJDK 21 package from its repository, resolve any dependencies, and install it on your system. Set the Java Environment: After installation, you may need to set the JAVA_HOME environment variable.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-install-java-on-mac
How to Install Java on Mac in 2026
February 20, 2026 - Follow the instructions at Install Homebrew. Run this command to check for an existing Java installation: ... You'll see one of two results. If Java is installed, you'll see output like this: openjdk version "25.0.1" 2025-10-21 LTS OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS) ...
🌐
Snyk
snyk.io › blog › install-java-on-macos
How to install Java on macOS | Snyk
April 17, 2024 - Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /opt/homebrew/Cellar/maven/3.9.5/libexec Java version: 21.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home Default locale: en_IL, platform encoding: UTF-8 OS name: "mac os x", version: "14.1", arch: "aarch64", family: "mac"
🌐
MacPaw
macpaw.com › how to › optimization › apps
How to install Java on macOS: a comprehensive guide
August 19, 2025 - Once Homebrew is installed, use this command to install OpenJDK: brew install openjdk@ followed by the version number for the version of OpenJDK you want to install. For example, for version 21, it would be brew install openjdk@21 · Press Return ...