Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JAVA_HOME in Mac permanently?

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?

like image 791
Vishal Tavande Avatar asked Feb 05 '13 08:02

Vishal Tavande


People also ask

Do I need to set JAVA_HOME on Mac?

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 ~/.

Where is JAVA_HOME set on Mac?

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 .


1 Answers

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 
like image 115
Jonas Rabbe Avatar answered Sep 28 '22 08:09

Jonas Rabbe