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

  • 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
    – mmmmmm
    Commented Mar 7, 2011 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? Commented Mar 7, 2011 at 15:49
  • Add: export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home in $HOME/.bash_profile Note: please remember to the Quit terminal and Open it again.
    – Jimmy_Rw
    Commented Sep 25, 2019 at 23:08

3 Answers 3


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.

  • my shell is Terminal.app. But why cannot it just work from the Property Editor List like other variables?
    – simpatico
    Commented Mar 6, 2011 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
    Commented Mar 7, 2011 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
    – mmmmmm
    Commented Mar 7, 2011 at 13:44
  • @simpatico, I don't know, I don't use a Mac
    – hasen
    Commented Mar 8, 2011 at 3:00

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.


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

  • 2
    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
    Commented Mar 6, 2011 at 18:14

Not the answer you're looking for? Browse other questions tagged .