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