4

I used the command brew install openjdk@11 to install Java on my mac. But when I run
java --version, I get the following message:

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java. I have a few questions:

  1. How do I install JRE using HomeBrew?
  2. Which JRE version do I need to install?
pensee
  • 375
  • 1
  • 10

1 Answers1

3

The answer to your question can be found by running:

brew info openjdk@11

Part of the output is:

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.

If you need to have openjdk@11 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
  • correct answer, but i will add that it's important to add the new jdk directory to the system path, or else you might end up referencing another java, /usr/bin/java in my case, even though the runtime points to the new brew install – blue_ego Nov 15 '22 at 11:17
  • You save my day buddy. Spend hours looking for it and your answer is the only one that has worked. Took the jenv route but it was not worthy, uninstall it already – Pablo Valdes Dec 16 '22 at 18:01