I am trying to set JAVA_HOME
by entering export JAVA_HOME=/Library/Java/Home
at terminal. It sets the JAVA_HOME
for current session.
How can I set it permanently?
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home , just export $JAVA_HOME in file ~/. bash_profile or ~/.
For older Mac OS X, the bash is the default Terminal shell, and we can set the $JAVA_HOME environment variable in either ~/. bash_profile or ~/. bashrc .
You can use /usr/libexec/java_home -v <version you want>
to get the path you need for JAVA_HOME
. For instance, to get the path to the 1.7 JDK you can run /usr/libexec/java_home -v 1.7
and it will return the path to the JDK. In your .profile
or .bash_profile
just add
export JAVA_HOME=`/usr/libexec/java_home -v <version>`
and you should be good. Alternatively, try and convince the maintainers of java tools you use to make use of this method to get the version they need.
To open '.bash_profile' type the following in terminal :
nano ~/.bash_profile
and add the following line to the file:
export JAVA_HOME=`/usr/libexec/java_home -v <version>`
Press CTRL+X to exit the bash. Press 'Y' to save changes.
To check whether the path has been added, type following in terminal:
source ~/.bash_profile echo $JAVA_HOME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With