Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my mac os 10.6.6 I'm trying to persist env variable $JAVA_HOME but it doesn't stick!

$ export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Once I restart it won't be set anymore. The GUI way to do that is to use the Property List Editor as documented by Apple and on SO. However, after a restart:

$ echo $JAVA_HOME

share|improve this question
The GUI way works for me in 10.6 what does your ~/.MacOSX/environment.plist look like and do you reset path in your shell and if do how –  Mark Mar 7 '11 at 13:42
If you're more interested in the GUI way there's a separate site dedicated to Apple questions; do you want this question moved there? –  Michael Mrozek Mar 7 '11 at 15:49
add comment

3 Answers

Running the 'export' command in a shell only persists it for the duration of the session.

Save the export command in ~/.bashrc (if your shell is bash). This way it's executed every time you start a new shell session.

share|improve this answer
my shell is Terminal.app. But why cannot it just work from the Property Editor List like other variables? –  simpatico Mar 6 '11 at 13:01
Terminal.app is the terminal window; bash is the default shell on OSX, and the shell that is probably running inside the terminal. –  geekosaur Mar 7 '11 at 8:46
The Property Editor list sets for apps launched from the GUI. This includes Terminal.app - however you can alther the variables in ~/.bashrc etc for commands run from the shell –  Mark Mar 7 '11 at 13:44
@simpatico, I don't know, I don't use a Mac –  hasenj Mar 8 '11 at 3:00
add comment

As mentioned by others, export only applies to the current shell and programs started from it after it is used. (Note that open relays its command to the Finder, so programs started that way don't get environment variables from the shell it's run in.)

One way to set environment variables persistently is to add to ~/.bash_profile or ~/.bashrc (the former is preferred, as otherwise subshells will override the export if you change it for some reason, say because you need a different JRE for some particular Java program). Another is to set them in ~/.MacOSX/environment.plist; this is the only way to set environment variables so that the Finder will see them.

I prefer to use the Environment Variable Preference Pane to manage ~/.MacOSX/environment.plist. You can also edit it by hand (watch out; it's XML). You will have to log out or reboot to get Finder to reread it after changing it.

share|improve this answer
add comment

For more information on how to set JAVA_HOME in Mac OSX, there is an existing post http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x

share|improve this answer
Instead of just saying "go here", perhaps you could give us a sample of what we'll find if we were to follow the link, and THEN give us the link? –  Kevin M Mar 6 '11 at 18:14
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.