Many Java applications that use shell scripts to configure their environment use the JAVA_HOME
environment variable to start the correct version of Java, locate JRE JARs, and so on.
On OSX 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
For me maven seems to work off the
.mavenrc
file:I'm sure I picked it up on SO too, just can't remember where.
As other answers note, the correct way to find the Java home directory is to use
/usr/libexec/java_home
.The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
To test whether it works, put in
it shows
you can also test
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I tend to use
/Library/Java/Home
. The way the preferences pane works this should be up to date with your preferred version.