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
In this article we show how to install Java on Mac using Homebrew, and how to allow to switch between different versions such as Java8, Java11, Java13 and latest Java version. Before we start, make sure you have Homebrew installed on your 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
🌐
Medium
medium.com › @dimitrios_ › brew-your-java-on-a-m1-a-quick-guide-c28d17f2d256
Brew your java on a M1: A Quick Guide | by Jim Kapsalis | Medium
September 30, 2024 - Check out brew search cask-versions/java for options. ... Run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk to make the system recognize your new JDK. ... This brief post provides a concise and informative guide to installing Java on a Mac M1 using Brew.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-install-java-on-mac
How to Install Java on Mac in 2026
February 20, 2026 - This is a good choice if you don't use Homebrew. See Install Java on Mac for detailed instructions. Homebrew formula. The command brew install openjdk@25 installs a Homebrew-managed build.
🌐
Medium
medium.com › @kirebyte › using-homebrew-to-install-java-jdk11-on-macos-2021-4a90aa276f1c
Using HomeBrew to Install Java JDK11 on MacOS (2021) | by Erick Gustavo López Siordia | Medium
August 5, 2021 - $ brew install java11 · If you skip this step the system won’t be able to find a java runtime for you to use. sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk · If you see something ...
Find elsewhere
🌐
Snyk
snyk.io › blog › install-java-on-macos
How to install Java on macOS | Snyk
April 17, 2024 - brew install maven · 4. Check Maven version: After the installation is complete, you can verify the installation by checking the Maven version: mvn -v · This command should return the installed version of Maven and show an output similar to the following: 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" If you prefer not to use Homebrew or if you encounter issues with it, you can also install Maven directly from the Apache source.
🌐
MacPaw
macpaw.com › how to › optimization › apps
How to install Java on macOS: a comprehensive guide
August 19, 2025 - For example, for version 21, it would be brew install openjdk@21 · Press Return and wait for the install to complete. If you don’t want to develop Java apps, but do want to be able to run them, you don’t need to install a Java SDK.
🌐
Oracle
java.com › en › download › help › mac_install.html
How do I install Java for my Mac?
4. Double-click on the .app icon to launch install Wizard. You might be prompted with message indicating app being downloaded from the Internet. Are you sure you want to open it? (See below screenshot as reference).
🌐
GitHub
gist.github.com › jonjack › 898efa5ccc79c140533ed53e0b1edbad
Install Java on Mac OSX via Home-brew · GitHub
brew tap caskroom/cask brew tap caskroom/versions // we will also install the handy cask completions. brew install brew-cask-completion · We can check the various releases of Java that are available.
🌐
Adam the Automator
adamtheautomator.com › install-java-on-mac
How to Install Java on Mac
November 30, 2022 - To install the latest version of Java on your Mac: 1. Run the below brew update command to update Homebrew.
🌐
Mac Install Guide
mac.install.guide › java › brew-cask
Brew Install Java - Easy Cask Method · 2026
Brew Install Java - Formula Method · Set JAVA_HOME · Java PATH · Java Version Managers · Install SDKMAN for Java · Update Java · Uninstall Java · Unable to locate a Java Runtime · Brew install Java on Mac. An easy Homebrew way to install the recommended Temurin 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 - % brew install adoptopenjdk14 installer: Package name is AdoptOpenJDK installer: Installing at base path / installer: The install was successful. package-id: net.adoptopenjdk.14.jdk version: 14.0.2+12 volume: / location: Library/Java/JavaVi...
🌐
Sourabh Bajaj
sourabhbajaj.com › java
Java | macOS Setup Guide - Sourabh Bajaj
openjdk version "13.0.2" 2020-01-14 ... you don't see the output like above then you need to install Java on your system · brew install openjdk ·...
🌐
GitHub
gist.github.com › tinkerware › 8d92524d78f958f3d821b127393a96a1
Maintaining Java Installs on macOS Using Homebrew Cask · GitHub
To install latest version of Java 9, run brew cask install java. The simple option is to set JAVA_HOME to symbolic link /Library/Java/Home, then point it to you desired JDK install: $ export JAVA_HOME="/Library/Java/Home" $ sudo ln -nsf ...
🌐
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.
🌐
Mac Install Guide
mac.install.guide › java › brew-formula
Brew Install Java - Formula Method · 2026
Brew install Java with the OpenJDK Homebrew formula. How to install the Java JDK with brew, add the required symlink, and configure Java correctly on macOS.
🌐
Medium
medium.com › w-logs › installing-java-11-on-macos-with-homebrew-7f73c1e9fadf
Installing Java 11 on MacOS with HomeBrew | by Wai Loon | w:Logs | Medium
January 27, 2019 - $ brew tap homebrew/cask-versions · 3. Install a specific version of the JDK such as java8, java10 or java for the current. $ brew cask install java · Add the following aliases to .bash_profile.