The Apple support website (https://support.apple.com/en-us/HT204036) links to Oracle's website, which only gives you an Intel version of the Java runtime.
Is there a way to obtain a Apple-Silicon version?
Cannot find java runtime on MacOS (M1 silicon) after installing openjdk - Stack Overflow
How to install Java on macOS Sonoma? - Apple Community
Could someone help me understand what this Java is for for my MacBook? Is it a necessary thing for a non tech guy?
Java Runtime for Apple Silicon
Videos
Factsheet
/ April 8, 2004
/ April 8, 2004
I also ran into this today.
After installing openjdk with brew install openjdk, I got this too:
java --version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
It seems there is already system-wide default java command/alias (I had no previous Java install), so let's show the details:
which java
/usr/bin/java
However reading the output of the brew install log one can see:
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
so, if you do not have another existing Java system-wide installation just run (and type your mac user password):
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Password:
Now it works:
java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)
Since you installed Java previously with homebrew, you can use the brew info command to see the details of your installation:
% brew info java
openjdk: stable 15.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/usr/local/Cellar/openjdk/15.0.1 (614 files, 324.9MB)
Poured from bottle on 2020-12-09 at 09:06:07
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: Cannot Represent