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 ...
🌐
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 ...
Discussions

macos - How to brew install java? - Stack Overflow
I assume this is my issue because the alias is not switching to different Java versions like it should and I am not sure how to correct it. 2023-09-21T22:26:32.117Z+00:00 ... You can use brew to install multiple Java versions and run a command to switch between the versions as required. More on stackoverflow.com
🌐 stackoverflow.com
brew list not showing everything that I installed
To reinstall 21.0.1, run: brew ... openjdk@21 $ brew deps --tree --installed | grep openjdk openjdk openjdk@11 openjdk@17 └── openjdk $ brew info openjdk@21 ==> openjdk: stable 21.0.1 (bottled) [keg-only] Development kit for the Java programming language https://open... More on github.com
🌐 github.com
1
1
January 12, 2024
where can i download java 21?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
16
3
June 23, 2024
Unable to install Java 8 on MBP M4
Use brew.sh Also Java 8 is… extremely old More on reddit.com
🌐 r/mac
15
2
January 13, 2025
🌐
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 › 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 ...
🌐
GitHub
gist.github.com › leifericf › f61c60a9ab889ed752f969e9db2009a0
Installing Java on macOS and Adding It to jEnv · GitHub
brew install --cask temurin8 · Make these Java versions known to jEnv: jenv add /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/ jenv add /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/ Use jEnv to set the global ...
🌐
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: ...
Find elsewhere
🌐
Uga
cobweb.cs.uga.edu › ~maria › classes › 2720-2025-Spring › Wk01-setup-brew.html
Installing JDK 21 on macOS and Windows
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 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 ·
🌐
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
🌐
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%
🌐
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 ...
🌐
Smart People I Know
smartpeopleiknow.com › 2023 › 10 › 23 › how-to-work-with-java-on-your-mac-including-having-multiple-versions-of-java-on-your-mac
How to work with Java on your Mac, including having multiple versions of Java on your Mac – Smart People I Know
October 23, 2023 - All you need is to enter the following: $ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” Now that you have homebrew installed, you can…
🌐
Homebrew
formulae.brew.sh › cask › temurin@21
Homebrew Formulae: temurin@21
brew install --cask temurin@21 · Name: Eclipse Temurin 21 · JDK from the Eclipse Foundation (Adoptium) https://adoptium.net/ Development: Pull requests · Cask JSON API: /api/cask/temurin@21.json · Cask code: temurin@21.rb on GitHub · Current ...
🌐
GitHub
gist.github.com › productinfo › ac0af7e776cd40aa7dbf62e08af807e3
How to install different Java Versions with Homebrew on MacOS · GitHub
Note that it's poured from the OpenJDK formula. $ brew install java # Install the most recent feature release of OpenJDK
🌐
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
🌐
Mac Install Guide
mac.install.guide › java › java-21
Install Java 21 on Mac · Mac Install Guide · 2026
How to install Java 21 on Mac step by step. Get the free Java 21 JDK for macOS, install with Homebrew or a PKG, verify the version, and set JAVA_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 - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" ... sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \ /Library/Java/JavaVirtualMachines/openjdk.jdk
🌐
GitHub
gist.github.com › tinkerware › 8d92524d78f958f3d821b127393a96a1
Maintaining Java Installs on macOS Using Homebrew Cask · GitHub
brew tap buo/cask-upgrade & brew tap caskroom/versions brew install --cask temurin8 # then echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.8)" >> ~/.zshrc