How to set JAVA_HOME environment variable on macOS?

user1872384 picture user1872384 · Sep 11, 2015 · Viewed 12.9k times · Source

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.

Answer

Peter Salomonsen picture Peter Salomonsen · Sep 11, 2015

in .bash_profile:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.xx/Contents/Home