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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…