Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?

Tags:

java

macos

Java is an optional package on the latest versions of macOS.

Yet once installed it appears like the JAVA_HOME environment variable is not set properly.

like image 977
Olivier Refalo Avatar asked Jul 05 '11 20:07

Olivier Refalo


People also ask

Where can I find JAVA_HOME in Mac?

Check you have the needed version of Java, by typing “java -version”. JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java. For Mac OSX – it is /Library/Java/Home.

What is JAVA_HOME Mac?

The JAVA_HOME environment variable contains the home location of an installed JDK. /usr/libexec/java_home is the simplest maintainable way of setting JAVA_HOME . Set JAVA_HOME to JDK version 1.7 export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


1 Answers

With the Java optional package or Oracle JDK installed, adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.

export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)" or export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)" or export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" or simply export JAVA_HOME="$(/usr/libexec/java_home)" 

Note: If you installed openjdk on mac using brew, run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk for the above to work

Update: added -v flag based on Jilles van Gurp response.

like image 73
Olivier Refalo Avatar answered Oct 14 '22 05:10

Olivier Refalo