Setting up Environmental Variable in Mac OS X Leopard 10.5.7

After a a month (to be honest, more than a month) of wandering, found a way to set the environmental variable in Mac OS X. It was not as straight forward as in Linux , (In Linux it is pretty much easier!!) rather needs some small tricks.

Here it goes,

The first and the easiest way is to set in .bash_profile or .bashrc, but in both the cases, the program might not see the environment variable (in my case this what happened). So go to the next alternative.

create, (if nothing exists already) ~/.MacOSX/environment.plist

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> mkdir .MacOSX
> cd .MacOSX
> touch environment.plist
> open environment.plist
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you have followed everything correctly, the following window will open


Click on the root to select and add an item and then enter your variable name as shown below.


The type should be string, since path is the string data type.

Enter your variable value as shown.


Save it.And that is all, your all done to make your environmental variable available for you to use.


But, this has a shortcoming, namely, if you would like to open terminal using spotlight, this environmental variable will not be in effect, means it will not be read when terminal starts (Have to really figure out how spotlight opens an application and where it looks for environmental variable settings).

If you are really a geeky and would like to explore anything to its core, you might be interesting with the following.

While just exploring OS X s process management, have figured out launchd has the process id of 1 (and it is run as root and not in usermode, I decided it should be the first process that starts, while Mac boots up). After, some searching, I confirmed my hypothesis is true at the following site,


As it was mentioned, I created a launchd.conf file and made my entry as below,

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> cd /etc
> vi launchd.conf

setenv VARIABLE "value" (don't use double quotes while you define your string value)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Voila......after a restart, it works like a charm!! Now even if I open terminal using spotlight, my environmental variable is read and in effect......!!

Comments