Home > Blockchain >  java_home issue on macbook 12.3.1 Monterey (M1)
java_home issue on macbook 12.3.1 Monterey (M1)

Time:07-16

java_home is not setup, Unable to locate a Java Runtime on Mac M1 (12.3.1 - Monterey)

openjdk is installed:

java --version
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)

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

I setup JAVA_HOME already in the profiles :

export JAVA_HOME=/opt/homebrew/Cellar/openjdk@11/11.0.15/libexec/openjdk.j/Contents/Home

CodePudding user response:

Unfortunately, java_home only looks for runtimes in 2 locations:

  • $HOME/Library/Java/JavaVirtualMachines
  • /Library/Java/JavaVirtualMachines

A symlink works but will need to be kept up-to-date as homebrew upgrades:

$ ln -sf /opt/homebrew/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk ~/Library/Java/JavaVirtualMachines/openjdk11

It then appears in the list in its original location:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    18.0.1.1 (arm64) "Homebrew" - "OpenJDK 18.0.1.1" /opt/homebrew/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/Contents/Home
    11.0.15 (arm64) "Homebrew" - "OpenJDK 11.0.15" /opt/homebrew/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk/Contents/Home
    1.8.0_332 (arm64) "Azul Systems, Inc." - "Zulu 8.62.0.19" /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
/opt/homebrew/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk/Contents/Home
  • Related