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?
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:
/etc/launchd.conf
The
launchd.conf
file is **the only complete solution that will work for both command line and GUI applications on OS X v10.8 (Mountain Lion) and v10.9 (Mavericks), one that will work with GUI and console applications, for all users.Add
In the example above I added
/usr/local/bin
to the default environment values for PATH.Keep in mind that this file is not a script and you do not have the option to use substitutions. Also, to have these applied you need to reboot.
Remember, all others are only partial solutions:
environment.plist
does not work for applications launched via Spotlight./etc/paths
- only for console/etc/csh.cshrc
or/etc/bashrc
- only for some shellsThis answer is based on the same question from Setting environment variables on Mac OS X.
You're going to have to set it on a shell-by-shell basis; Bash and csh-like shells do not share the same configuration files and syntax for adjusting the PATH.
Trying to do this in
launchctl
will not work, because environment variables are set on login; they do not exist system wide in Unix outside of a shell session.So you're going to want to add
to
/etc/csh.cshrc
andto
/etc/bashrc
.If you want environment variables in GUI applications, that's more complicated. You have to create a
.MacOSX/environment.plist
file in each user's home directory. The.MacOSX
directory will likely not exist by default, so you'll have to create it.The format of the file is like so:
More on the
environment.plist
is on Apple's site.You can edit your global path by adding lines to
/etc/paths
, one path per line.sudo nano /etc/paths
should get you there.Have you had a look at the man page for the
path_helper
command-line utility on OS X? I answered a somewhat related question on SO that I think you may find helpful.I am not sure if anyone covered the simplest and most elegant way. At least on Mac OS X v10.6 (Snow Leopard).
Messing with the
[/etc/|~/.]
of[profile|bashrc]
files may work, but it's somewhat of a hack. The/etc/paths.d/
directory is the way to go:Create a new file named
*name*
(just don't name it something that's already in there) in/etc/paths.d/
with a path per line:Then add
to
profile
orbashrc
, and you should be good to go.I'm not sure if launchd accepts this, but try:
I'm not sure why you'd use
/etc/launchd.conf
as opposed to/etc/profile
- but I'm no expert in Mac OS X - I believe you in that I'm sure it works, butlaunchd
is the Mac OS X implementation/replacement forinit
- Mac OS X confuses me.Anyway,
setenv PATH "$PATH:/more/paths:/and/more/paths"
will work (tcsh), and the bourn shell equivalent isexport PATH="$PATH:/more/paths:/and/more/paths"
- I have no idea howlaunchd
is related to a particular shell either.I think I've asked more questions then I've answered =)