How do I set environment variables on OS X?
I have always difficulties setting the Environment variables in OS X like JAVA_HOME
, M2_HOME
or PATH
. How to set these on OS X Mavericks?
I did some research but the answers I've found didn't really help me yet:
-
export JAVA_HOME=/...
(But it seems that the changes are temporary, just for one terminal session.) -
setenv JAVA_HOME=/...
(But command not found.) - Open
.profile
and write the variables inside to make the changes permanent- (.profile
does not exist). - Open
.bash_profile
and write the variables inside to make the changes permanent- (.bash_profile
does not exist). -
vi ~/.bash_profile
(Quite a challenge for somebody who doesn't knowvi
.) - Creating your own
enrivonment.plist
file.
Can somebody please walk me through the steps to get that to work on OS X Mavericks, assuming no Unix knowhow?
I have a .profile in my home directory; it contains many export …
statements for environment variables.
You can create such a file by opening a Terminal and issuing the command touch .profile
Close Terminal.
Then you should open that file in a plain-text editor (TextWrangler for example). You can also use nano .profile
in a Terminal window (current directory should be your home), which is much easier than vi
. Insert lines such as export JAVA_HOME=…
. Save, exit nano
if you used that and quit a running Terminal.
Open Terminal and issue the command env
to see all environment variables. Check that the ones you defined have the value you assigned to them. You should be good to go now. But don't forget that environment variables defined in .profile
are not passed to GUI applications.
In Yosemite, you should put export VARIABLE='something'
inside .bash_profile
.
I've tried writing the export VARIABLE='something'
inside .profile
without success.