I recently got this new MacBook Pro (2021) 16" with MacOs Monterey and trying to install Java (openjdk11). I installed Homebrew and used brew install openjdk@11 to install java. I get following when executed java --version command,
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
But when I execute /usr/libexec/java_home, I get the following,
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Which I also had set as my JAVA_HOME after adding JAVA_HOME=$(/usr/libexec/java_home) to ~/.zshrc.
Even the folder /Library/Java/JavaVirtualMachines/ is empty.
Tried uninstalling according to www.java.com and then reinstall using brew but still getting the same issue.

On the Homebrew OpenJDK formula page (last check: 19 dec 2022), there is this note that says:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
If like me you need the JAVA_HOME variable in your shell, you can add this in your ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home)
(Tested with MacOS Monterey and Ventura update).
Could not solve the Original Problem then used brew install --cask temurin11 (https://adoptium.net/installation/) and installed Java with no problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With