Bookmark this site!


Setting environment variables

There is a special environment file which loginwindow reads each time a user logs in. The environment file is: ~/.MacOSX/environment.plist

Dot files aren't, by default, visible in the finder, so type cd; open .MacOSX in a terminal. If the environment.plist file is there you can open it in the Property List editor with a doubleClick. Otherwise, you will have to create the .MacOSX directory yourself.

To create the directory and file
$ cd
$ mkdir .MacOSX
$ echo "" > .MacOSX/environment.plist
$ open .MacOSX/environment.plist

This should open your new, empty environment.plist file in the Property List Editor. Select Root and Add a Child: the Key should be the name of the variable you want to set; Type should be String; Value should be the value you want to set for this variable. Next time you log in the variables should be set.

Environment variables set in environment.plist also appear in the standard bash environment. You can see all your environment variables using the shell command env from a Terminal window.


WARNING: do not set the DISPLAY variable—see my post re. X11 on Leopard.


Ketema said...

How do you set them for the system globally at start up ?

Donald Bruce Groover said...

Thanks! This is just what I was looking for. I like it because its direct and to the point.

Peter Barry said...

I agree good simple post on this, funny I looked a few previously that managed to confuse such a simple process.

Henry Warmoth said...

I didn't realize this right away, but you won't see the variable you've just set in the output of `env` until after restarting/log out+in

Tim said...

If it opens in your text editor, first download the "Plist Editor Pro" from apple's developer site.

Mac Guider said...

I'm trying to set environment variables for MAC for cakephp.

Henry said...

Can you set the variable to a path name

Deepu V S said...

In system lik Mac which is very abstracted for developers, these tips are very usefull.

Anonymous said...

Great thanks!

eco tech said...

Very good blog. thanks for the input. all working!