1

I'm on macOS monterrey and using a custom JDK 15 (I have to use a custom JDK modified for my company). When I run /usr/libexec/java_home I get this error:

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

however when I run echo $JAVA_HOME I get /Library/Java/JavaVirtualMachines/openjdk_15.0.6_15.38.18_x64. In addition running java --version return the correct JDK version.

Because /usr/libexec/java_home doesn't point to the actual JDK directory tools which use Java don't work.

Is there a way to set /usr/libexec/java_home to point to my JDK directory?

hitchhiker
  • 1,217
  • 4
  • 13
  • 28

1 Answers1

1

See these questions for a deep dive into this topic:

How can I change Mac OS's default Java VM returned from /usr/libexec/java_home

How to set or change the default Java (JDK) version on macOS?

Here is a short answer that works:

sudo ln -s (absolute path to your JVM) /Library/Java/JavaVirtualMachines/(symlink name)

In my case, it points to the JVM in the latest Android Studio:

sudo ln -s /Applications/Android\ Studio.app/Contents/jre /Library/Java/JavaVirtualMachines/android-studio-jre
c4augustus
  • 136
  • 1
  • 6