Possible Duplicate:
Setting JAVA_HOME environment variable

When you type "echo $JAVA_HOME" in Mac, where does Mac look to find the value of JAVA_HOME? In other words where does Mac save environment variables?

marked as duplicate by Dennis Williamson, Mehper C. Palavuzlar, Sathyajith Bhat, Nifle Feb 3 '11 at 5:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jan 31 '11 at 19:47

This question came from our site for professional and enthusiast programmers.

  • Your question asks "where does OS X save environment variables?" Although the answers have discussed how to set variables, is this really what you're asking? If so, then the answer is "in the environment"! Each process (ie each application, and each command run from the command line) has an environment which stores, amongst other things, the set of variables. When you create a new process (for example you create a new terminal window, or run a new program) the new process gets a copy of the environment of the current process, including any variables you've set in that process. W – Norman Gray Feb 2 '11 at 19:24

A similar question/answer was posted on stackoverflow. The solution describes that you should create a ~/.profile and define the environment variables at this level. You can check out the Apple Reference Library on setting environment variables for additional information.


In your home directory's .profile file. (ex: /Users/Mahdi/.profile)


Environment variables may be defined in all the usual places for a bash shell session. There is also an optional special file $HOME/.MacOSX/environment.plist which can contain environment variables for apps etc.


Put this: export JAVA_HOME=/Library/Java/Home (or location of your Java lib) in ~/.bash_profile

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