You have to install the full JDK, not only the JRE.

I had the same issue and solved by installing JDK.

Please use this link to download the latest JDK version 22.

Answer from MrDEV on Stack Overflow
Top answer
1 of 16
255

You have to install the full JDK, not only the JRE.

I had the same issue and solved by installing JDK.

Please use this link to download the latest JDK version 22.

2 of 16
210

After installing openjdk with brew and runnning brew info openjdk I got this:

==> openjdk: stable 21 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk/21 (600 files, 331MB)
  Poured from bottle using the formulae.brew.sh API on 2023-09-26 at 11:06:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔, pkg-config ✔
Required: giflib ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, little-cms2 ✔
==> Requirements
Build: Xcode (on macOS) ✘
Required: macOS >= 10.15 (or Linux) ✔
==> Caveats
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

openjdk is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"

And from that I got this command here, and after running it I got Java working

sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Discussions

Can't find Java runtime on macOS (when installed using Homebrew)
I tried to run version 1.9.0 from KiCAD 8 on macOS 14. It didn't find the installed java runtime. The easy fix was to go into the plugin.ini and change the java path from java to /opt/homebrew/... More on github.com
🌐 github.com
24
February 24, 2024
In Terminal getting error: The operation … - Apple Community
I installed Java using the link, but still no-go. The command that generated this error was: apt update ... The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. More on discussions.apple.com
🌐 discussions.apple.com
June 15, 2023
Cannot find java runtime on MacOS (M1 silicon) after installing openjdk - Stack Overflow
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. More on stackoverflow.com
🌐 stackoverflow.com
macos - How to brew install java? - Stack Overflow
How can I install latest java using brew? ... 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) ... The operation couldn’t be completed. Unable to locate a Java Runtime. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Apple Developer
developer.apple.com › forums › thread › 687489
Java Runtime not found | Apple Developer Forums
I would recommend fixing this issue fully by first removing the Java you installed by running the following in your terminal: sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\ Support/Oracle/Java · And then reinstalling the JDK via brew by running: brew reinstall adoptopenjdk8
🌐
GitHub
github.com › orgs › Homebrew › discussions › 2405
mac version 11.6 , M1, brew install openjdk@11 · Homebrew · Discussion #2405
For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk openjdk@11 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula.
Top answer
1 of 5
5

It seems that you are missing Java environment variable to make your program work.

What you can try:

Solution 1

Try to run caver_analyst with the --jdkhome switch, followed by (I guess) the path to a valid JDK as suggested in your error message. It should solve your problem.

Solution 2

Usually, the path to Java must be defined in a JAVA_HOME environment variable. Yours is obviously not defined, so let's define it manually :

  1. Open a Terminal
  2. Go to your home directory with command cd
  3. Look for a file called ".zshrc" in this directory:
you@yourmac ~ % ls .zshrc
.zshrc
  1. If it does not exist i.e. if the command ls .zshrc gives you a "No such file or directory" message, create the file: touch .zshrc
  2. Get the path to Java and keep it somewhere : which java
  3. Open the newly created file (it's a hidden file so you will have to show hidden files. Alternatively, you can edit the file in command line with nano .zshrc)
  4. At the end of the file, add the following line : export JAVA_HOME="/Path/to/your/java/home" and replace /Path/to/your/java/home with the path that you got at step 5.
  5. Save, close the file, reboot your laptop.

This file will be automatically read and its instructions executed when you open your profile. The "export" instruction creates an environment variable. You can verify if it was successfully created with echo $JAVA_HOME, echo being a command to display something. The "$" in front of the variable tells echo to look for a variable.

I hope this helps, but if it doesn't, please don't hesitate to share the error messages and step where it fails here...

2 of 5
5

I had to

  • Install Java 8, eg
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
  • add $JAVA_HOME to my ~/.zshrc
export JAVA_HOME='/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home'
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
  • remove any other jdk installs
ls /Library/Java/JavaVirtualMachines
sudo rm -rf NONJDK8.jdk

The 3rd bit is important! It did not work until I removed other-versioned jdks.

🌐
Mac Install Guide
mac.install.guide › java › unable-to-locate
Fix "Unable to Locate a Java Runtime" - Mac Install Guide
Many Java tools (Maven, Gradle, IDEs) use the JAVA_HOME environment variable to locate Java: ... This should return a path like /Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home. If it returns nothing, JAVA_HOME isn't set. See the article Set JAVA_HOME. ... If Java isn't installed, Homebrew provides the simplest installation method. Homebrew handles updates automatically, provides native Apple Silicon builds, and keeps paths consistent across Macs. ... Cask (Temurin) – Command: brew install --cask temurin@25, configuration is automatic, and it's best for most developers.
🌐
GitHub
github.com › freerouting › freerouting › issues › 277
Can't find Java runtime on macOS (when installed using Homebrew) · Issue #277 · freerouting/freerouting
February 24, 2024 - I tried to run version 1.9.0 from KiCAD 8 on macOS 14. It didn't find the installed java runtime. The easy fix was to go into the plugin.ini and change the java path from java to /opt/homebrew/...
Author   freerouting
Find elsewhere
🌐
Andrew Hoog
andrewhoog.com › posts › 3-ways-to-install-java-on-macos-2023
3 ways to install Java on macOS [2023] - Don't Panic
January 12, 2023 - $ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk $ java -version ... openjdk version "19.0.1" 2022-10-18 OpenJDK Runtime Environment Homebrew (build 19.0.1) OpenJDK 64-Bit Server VM Homebrew (build 19.0.1, mixed mode, sharing) For the last option, we’ll try SDKMAN! which is a tool I’ve not used to date (side note: I hate having to capitalized and use an exclamation point every time I reference to tool!). Unlike brew’s broad approach, SDKMAN!
🌐
Apple Community
discussions.apple.com › thread › 254929839
In Terminal getting error: The operation … - Apple Community
June 15, 2023 - With the prerequisites installed, if invoking the install.sh script from the proper default directory does not work, I would suggest discussing these install issues with the app provider. Open an issue on GitHub, or whatever forums the app provider might prefer. For reference, some other open issues with that app: https://github.com/ultrasecurity/Storm-Breaker/issues ... Is there a command for Apt on Mac? is there a command for apt on mac? Got error 'The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
Top answer
1 of 4
19

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)
2 of 4
1

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
🌐
Stack Overflow
stackoverflow.com › questions › 70768763 › unable-to-locate-java-runtime-environment › 70769058
homebrew - Unable to locate Java Runtime Environment - Stack Overflow
Weirdly enough, I solved it by simply downloading the latest Java 8 dmg from the java website and installing it. ... Which dmg exactly? It is great that you want to help future readers with the same problem, but then: you need to be much more ...
🌐
Marco Gomiero
marcogomiero.com › posts › 2021 › kmp-no-java-runtime-error-xcode
How to fix the "Unable to locate a Java Runtime" error on Xcode with Kotlin Multiplatform - Marco Gomiero
December 27, 2021 - Unable to locate a Java Runtime. Still strange. I usually install the JDK manually with Homebrew, but for this time I decided to give sdkman a try. And that was the problem because sdkman “doesn’t expose” the JDK version to /usr/libexec/java_home. So I went back to the old and good manual way. Since the AdoptOpenJDK tap is deprecated, I tried the Temurin one and installed Java 11 and Java 8. brew tap homebrew/cask-versions brew install --cask temurin8 brew install --cask temurin11
🌐
Snyk
snyk.io › blog › install-java-on-macos
How to install Java on macOS | Snyk
April 17, 2024 - In the above lines of code, `$(/usr/libexec/java_home)` dynamically finds the path of the current JDK installation. Save the file and exit. To ensure the changes take effect, either restart the Terminal or run the following command: ... To verify the installation and the environment variable setting, you can use the Terminal to display the version of the installed JDK. Run the following command: ... openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.2+9) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.2+9, mixed mode)
🌐
Apple Community
discussions.apple.com › thread › 254552020
Unable to locate a Java Runtime that supp… - Apple Community
January 13, 2023 - If installed you can install packages with "brew install [packagename]" ... In Terminal getting error: The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt. Please visit http://www.java.com for information on installing Java.
🌐
Pi My Life Up
pimylifeup.com › home › how to install java on a mac
How to Install Java on a Mac - Pi My Life Up
April 21, 2023 - 4. You should now be able to run the following Java command in the terminal without seeing an error. ... If you did not use the symlink command, you must enter the command below. ... After running either of the commands above, you should have an output similar to the example below. openjdk 20 2023-03-21 OpenJDK Runtime Environment Homebrew (build 20) OpenJDK 64-Bit Server VM Homebrew (build 20, mixed mode, sharing)
🌐
freeCodeCamp
freecodecamp.org › news › how-to-install-java-on-mac
How to Install Java on Mac in 2026
February 20, 2026 - If you previously installed Java but see this dialog, something is wrong with your installation. See Unable to Locate a Java Runtime for troubleshooting.
🌐
Code2care
code2care.org › home › macos › fix [mac terminal] the operation couldn’t be completed. unable to locate a java runtime. (update for ventura/sonoma)
Fix [Mac Terminal] The operation couldn’t be completed. Unable to locate a Java Runtime. (update for Ventura/Sonoma) | Code2care
September 10, 2023 - If you get the above error, instead of version details, follow this article to install brew on your Mac - https://code2care.org/howto/install-homebrew-brew-on-m1-mac ... Note: There is only x86_64 support for Java 8 so won't work on M1/M2 based Mac.
🌐
John Siu
johnsiu.com › blog › macos-brew-java
John Siu Blog | MacOS Homebrew Java/JDK
However when executing java from command line, error pop up: ... Most brew packages display extra steps during installation, if required. However, they are easy to miss when installing multiple packages.