Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JAVA_HOME environment variable on macOS?

According to this mobilefirst tutorial, it mentioned:

You must have the JAVA_HOME environment variable set to your JDK directory.

For example:

Mac OSX: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home

I've added this 2 lines in .bash_profile:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export PATH=$PATH:$JAVA_HOME/Contents/Commands

Is this correct?

Thanks.

like image 447
user1872384 Avatar asked Sep 11 '15 07:09

user1872384


Video Answer


1 Answers

If your default terminal is /bin/zsh (Z Shell) like in my case, then you should set these environment variable in ~/.zshenv file with following contents:

export JAVA_HOME="$(/usr/libexec/java_home)"

Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.

After saved the content into env file, restart terminal and call following commands:

echo $JAVA_HOME

It should display the full Java path.

like image 135
Jerry Chong Avatar answered Oct 08 '22 00:10

Jerry Chong