bashmacosjava-home

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.


Solution

  • in .bash_profile:

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