Home > Mobile >  jvm path not found on mac
jvm path not found on mac

Time:03-16

I have installed java11 using

brew install java11

Then I tried the below to get JAVA_HOME

echo $JAVA_HOME

It returned empty . so following the instructions in echo $JAVA_HOME returns nothing

when I have run ls -l /usr/bin/java i cannot see any jvm path as shown in the above link. Below is what I got

 ~ % ls -l /usr/bin/java
-rwxr-xr-x  1 root  wheel  168432 Dec  8 05:09 /usr/bin/java

ls -l /usr/lib/jvm/
ls: /usr/lib/jvm/: No such file or directory

How to set JAVA_HOME

CodePudding user response:

If you're using bash, all you have to do is:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile

If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc

In either case, restart your shell.

If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:

echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile
  • Related