Tuesday, November 18, 2014

Set $JAVA_HOME on OSX 10.9 (Maverick)

By default, jdk is pre-installed on OSX 10.9. Running the following command:

$java -version

The above commands show the following information:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)

Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

However, if user runs the following command to check the $JAVA_HOME:

$echo $JAVA_HOME

the terminal will returns an empty string, to set the $JAVA_HOME environment variable, go to the home directory first:

$cd $HOME

then open the .bash_profile to edit:

$open .bash_profile

Add the following line to the end of .bash_profile:

export JAVA_HOME=$(/usr/libexec/java_home)

Save and close the .bash_profile. Now run the following command to update the environment var:

$source .bash_profile

Now again enter the following command:

$echo $JAVA_HOME

The terminal will print out:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

No comments:

Post a Comment