System-wide environment variables in OS X 10.6 Snow Leopard

Normally adding variables to .profile/bash.rc/etc. only makes them visible to Terminal, but not to GUI Applications. This is how to make them global:

launchctl setenv MY_VAR MY_VALUE

But they’ll only last until next login.
How to make persistent environment vars?
This post at stackoverflow suggests to put them into ~/.launchd.conf like this:

echo setenv MY_VAR MY_VALUE >> ~/.launchd.conf

But I found, that defining or appending PATH in ~/.launchd.conf doesn’t work on 10.6. PATH is overwritten by ~/.MacOSX/environment.plist. So I stick with the latter file, simply editing it using the Property List Editor that comes with OS X.
After editing it you have to either log in again or do…

launchctl setenv MY_VAR MY_VALUE

…to set it just for the current session.

Leave a Comment