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 OverflowHomebrew
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 ...
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
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
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
Unable to install Java 8 on MBP M4
Use brew.sh Also Java 8 is… extremely old More on reddit.com
Videos
04:08
How to Install Java JDK on Mac Using Homebrew (2025 Easy Guide) ...
How to Install Java 21 On MacOS using Homebrew - openjdk | Mac ...
13:58
How to Install Java JDK on Mac OS and set JAVA HOME variable - YouTube
How to Install Latest Java version On Mac using Homebrew | Mac ...
13:09
How to install Java 21 on Mac M1,M2, MacBook on macOS Ventura || ...
10:24
How to install Java JDK 21 on MacBook, macOS Sonoma - YouTube
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 ...
Top answer 1 of 14
805
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
2 of 14
137
As an add-on to the accepted answer: to install a certain version of Java, e.g. version 11, run:
brew install openjdk@11
And symlink it:
sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-11.jdk
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: ...
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 ·
GitHub
github.com › AdoptOpenJDK › homebrew-openjdk
GitHub - AdoptOpenJDK/homebrew-openjdk: AdoptOpenJDK HomeBrew Tap · GitHub
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 ...
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.
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
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
Homebrew
formulae.brew.sh › cask › microsoft-openjdk@21
Homebrew Formulae: microsoft-openjdk@21
brew install --cask microsoft-openjdk@21 · Name: Microsoft Build of OpenJDK · OpenJDK distribution from Microsoft · https://microsoft.com/openjdk · Development: Pull requests · Cask JSON API: /api/cask/microsoft-openjdk@21.json · Cask ...