Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 725
Gickian Avatar asked Aug 23 '12 10:08

Gickian


People also ask

What should JAVA_HOME be 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 ~/. profile .


2 Answers

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
like image 138
tokhi Avatar answered Oct 18 '22 02:10

tokhi


I created a file ~/.bash_profile and added:

export PATH=/usr/local/mysql/bin:$PATH
export PATH=/Users/sparkyspider/dev/javalibs/Grails/grails-2.1.1/bin:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

And all's working great for me...

like image 25
sparkyspider Avatar answered Oct 18 '22 00:10

sparkyspider