I'd like to append to the global PATH 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 coulnd'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. Does anyone know of a better way?
-
I'm not sure if launchd accepts this, but try:
setenv PATH "$PATH:/my/path"
lajos : Unfortunately that doesn't work. It doesn't look like launchctl has access to environment variables that easy. There is a command to get environment variables, but there's absolutely no documentation on how to use it.From grawity -
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 =)
lajos : /etc/profile path settings are not seen by any of the OS X GUI apps. That only applies to bash. I want all applications to get the new path setting.Xerxes : Right - thanks for clearing that up for me :)Matt Simmons : Unix? Sure, it's unix. I mean, sorta. Yea, we broke stuff that's worked for 30 years, but it's still unix! /sighFrom Xerxes -
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
setenv PATH "$PATH:/add/my/extra/path"
to /etc/csh.cshrc and
export PATH="$PATH:/more/paths:/
to /etc/bashrc.
If you want environment variables in GUI apps, 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:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PRINTER</key> <string>myprinter</string> <key>PATH</key> <string>/path/to/thing/I/need</string> <key>DISPLAY</key> <string>0:1</string> </dict> </plist>
More on the environment.plist is on Apple's site.
Xerxes : But the settings do take effect when set in /etc/launchd.conf... Hmmm... /me is confused.palmer : Really? What environment variable are you setting there?From palmer -
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.From ayaz -
What exactly are you trying to do? Maybe is there a better way than creating that kind of "global" path...
-
You can edit your global path by adding lines to /etc/paths.
One path per line.
sudo nano /etc/paths should get you there.
From mediaslave -
palmer's GUI info 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
From cogg
0 comments:
Post a Comment