How to Set Java JDK Environment Variable for Mac OS X 10.8 Mountain Lion

Gickian picture Gickian · Aug 23, 2012 · Viewed 61.5k times · Source

Can anybody tell me how to set environment variable for Mac OS X 10.8 Mountain Lion. I just upgrade my Mac to Mac OS X 10.8. When I run a script. It said that

"/Users/ruijiaoli/lejos_nxj/bin/nxj: line 64: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java: No such file or directory"

I found that JDK in the directory within the path above. And it worked well in Mac OS X lion. Is the JDK path changed in Mac OS X mountain Lion? The version of Java on my system is 1.6.

Answer

tokhi picture tokhi · Jan 6, 2014

This is what I have tried:

create the bash_profile:

$ vim ~/.bash_profile 

add this to the file:

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

execute the source command

$ source ~/.bash_profile

echo JAVA_HOME:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home