How to set the global PATH environment variable on OS X

mac-osxpath

I'd like to append to the global PATH environment variable on OS X so that all user shells and GUI applications get the same PATH environment.

I know I can append to the path in shell startup scripts, but those settings are not inherited by GUI applications.

The only way I found so far is to redefine the PATH environment variable in /etc/launchd.conf:

setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/my/path

I couldn't figure out a way to actually append to PATH in launchd.conf.

I'm a bit worried about this method, but so far this is the only thing that works. Is there a better way?

Best Answer

palmer's GUI information is correct, but there is a more maintainable way to modify the path seen by the shell. Like mediaslave said, you can edit /etc/paths, but even better you can drop a text file in /etc/paths.d/ that has a path in it and all shells will construct the path correctly.

For example, on my system:

$ cat /etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
$ ls /etc/paths.d
X11       git      postgres
$ cat /etc/paths.d/postgres
/Library/PostgreSQL/8.4/bin
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Library/PostgreSQL/8.4/bin:/usr/X11/bin:/usr/local/mysql/bin
Related Topic