14

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.

Gickian
  • 253
  • 2
  • 3
  • 8

3 Answers3

28

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
tokhi
  • 21,044
  • 23
  • 95
  • 105
12

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

sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • Where did you placed the file? – Bogdan Jan 14 '13 at 11:03
  • ~ represents the user directory, so in other words /Users/user/.bash_profile – sparkyspider Jan 14 '13 at 15:35
  • 2
    That method works only for the user's own environment. If you need such environment variables as a system-wide level, apparently you need to put corresponding setenv commands into a file /etc/launchd.conf. – murray Mar 05 '13 at 17:06
  • Hi @Bogdan, "~" meaning user home directory. Example "/Users/ravi". So ".bash_profile" should be in "/Users/ravi/" – Sun Oct 01 '17 at 17:29
0

I've found the following post very helpful -

http://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/

It explains how to set the path for a single user or system wide (OS X Leopard+)

darkCode
  • 140
  • 8