Environment variables that are set in ~/.MacOSX/environment.plist are available to all applications, not just the Terminal, however it can only set user specific environment variables.

Note This is not supported in Mac OS X 10.8 and higher. Try instead with HowTo: Set an Environment Variable in Mac OS X - launchd.plist
Note For Mac OS X 10.5 and earlier, applications started from spotlight do not have access to these environment variables.

By default, the ~/.MacOSX/environment.plist file does not exist, so we will have to create it. Once created we will need a program that can edit .plist files, such as Xcode.

Open the Terminal program, you’ll find it in the Utilities folder in the Applications folder, and issue the following command to create the .MacOSX directory:

Terminal - hostname:~ user$

1
mkdir -p ~/.MacOSX

Now we’ll create the environment.plist file:

Terminal - hostname:~ user$

1
echo "" > ~/.MacOSX/environment.plist
Be Aware When using touch ~/.MacOSX/environment.plist instead, Xcode complains The data couldn't be read because it has been corrupted..

Now we can open the file

Terminal - hostname:~ user$

1
open ~/.MacOSX/environment.plist

Right click on the window and pick Add Row

Set the key

Set the value

We’re done adding this environment variable.

Save the file and quit. Go to the apple menu and log out. Log in again and your environment variable is set.

Resources

Parts of this series