10

OK, apologies if this is something dumb, but I'm running out of ideas.

Goal: prepend /usr/local/bin to $PATH

Problem: $PATH won't do what I want or expect

How I got here: I want to start learning to program, so I'm getting comfortable messing around under the hood, but don't have a lot of experience. I installed the fish shell (because it's friendly!) using homebrew and set it as my default shell (under system prefs>users & groups>advanced). At some point, I ran brew doctor to see if my installs were all kosher, and it suggested I move /usr/local/bin to the front of $PATH so that I could use my installation of git rather than the system copy. Fine - but between path_helper and fish, something was happening to $PATH that was out of my control, and I could never get the paths arranged in the right way.

Environment: OSX 10.8.2, upgraded from 10.7ish, with xcode and devtools installed, plus x11, homebrew, and fish

More info: I've set my user's default shell back to bash, and tried a variety of shells thru terminal.app - bash, fish, sh. I moved /usr/local/bin to the top of /etc/paths but it didn't change anything. I looked thru the various config.fish files and commented out stuff that might mess with $PATH, didn't help. I have the following files in /etc/paths.d/:

./10-homebrew containing /usr/local/bin

./20-fish containing /usr/local/Cellar/fish/1.23.1/bin

./40-XQuartz containing /opt/X11/bin

I added set +x to my profile and when I start terminal.app I get:

Last login: Mon Oct  1 13:31:06 on ttys000
+ '[' -x /usr/libexec/path_helper ']'
+ eval '/usr/libexec/path_helper -s'
++ /usr/libexec/path_helper -s PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Cellar/fish/1.23.1/bin:/opt/X11/bin";
export PATH;
+ '[' /bin/bash '!=' no ']'
+ '[' -r /etc/bashrc ']'
+ . /etc/bashrc
++ '[' -z '\s-\v\$ ' ']'
++ PS1='\h:\W \u\$ '
++ shopt -s checkwinsize
++ '[' Apple_Terminal == Apple_Terminal ']'
++ '[' -z '' ']'
++ PROMPT_COMMAND='update_terminal_cwd; '
++ update_terminal_cwd
++ local 'SEARCH= '
++ local REPLACE=%20
++ local PWD_URL=file://Chriss-iMac.local/Users/c4
++ printf '\e]7;%s\a' file://Chriss-iMac.local/Users/c4 
Chriss-iMac:~ c4$

So it looks like path_helper runs, but then running echo $PATH nets me /usr/bin:/bin:/usr/sbin:/sbin. So, it looks like path_helper isn't even doing what it's supposed to anymore?

I'm sure there is some well-defined behavior here that I don't understand, or I borked something while trying to fix it. Please help!

1
  • note, I can get it to work for fish by creating ~/.config/fish/config.fish with set PATH /usr/local/bin $PATH but I still have the issue of path_helper apparently not working like it should, and $PATH thus being incomplete. Also still have the issue of different $PATH for scripts, apps started from the GUI, etc.
    – Chris4d
    Commented Oct 1, 2012 at 22:36

3 Answers 3

5

solution:

choose if you want a system wide setting or an user config and edit the appropriate configuration file, don't use path_helper with fish.

more

fish doesn't source /etc/profile, for system wide and user config it'll read /etc/fish/config.fish and ~/.config/fish/config.fish respectively [1].

path_helper is meant for using for shells that source a system wide profile file (sh, csh and their derivates). Since 10.7 path_helper seems to honor order in /etc/paths, AFAIR it didn't in 10.6 and that was harder to cope with.

If you really want to use path_helper with fish you'll need to parse its output since it'll only provide sh and csh syntax with -s and -c options.

Something like

/usr/libexec/path_helper -c | sed -e 's/setenv/set -x/' -e 's/:/ /g' -e 's/[";]//g'

should do the job:

[1] http://ridiculousfish.com/shell/user_doc/html/index.html#initialization

1
  • Great! This is what I have now: if status --is-login eval (/usr/libexec/path_helper -c | sed -e 's/setenv/set -x/' -e 's/:/ /g' -e 's/[";]//g') end - works fine here with fish 2 and Mac OS 10.8.3
    – topskip
    Commented May 22, 2013 at 9:12
3

I have absolutely no idea about /etc/paths.d, path_helper, &c., all of which seem like excessive complications to me, but the following at the end of your ~/.bashrc should put you right:

 PATH=/usr/local/bin:$PATH

Hope this helps!

2
  • Thanks Aaron - path_helper is an OSX-specific utility that supposedly sets $PATH at login by reading from /etc/paths and then /etc/paths.d/*. Anyway, I understand your suggestion should fix me for bash, but I actually want it to work in fish (and consistently across the system, if that's not too much to expect).
    – Chris4d
    Commented Oct 1, 2012 at 21:23
  • Ah -- sorry about that. I'm not an OS X user myself, more's pity, but from a bit of Google-bashing it looks as though this Stack Overflow question might be more like what you're after -- that said, again, I'm not an OS X user myself, and only responded because a quick (read: careless) look at your question made me think you were only interested in bash, so take my advice here with several grains of salt. Hope it helps, all the same -- Commented Oct 1, 2012 at 22:04
3

Thanks to Aaron for responding and for all those who answered other similar questions on the stackexchange sites. For posterity's sake, here is what I figured out:

  1. path_helper is called from /etc/profile, by the syntax eval '/usr/libexec/path_helper -s' (where the apostrophes are actually backticks). Like a dummy, I didn't know how backticks worked, and so had changed them to quotes for some reason. This broke my profile from loading path_helper. Replaced the back-ticks and now it works like it should (of course).
  2. using set PATH /usr/local/bin $PATH in my ~/.config/fish/profile.fish ensures that I get the right order in my preferred shell, but as long as path_helper works it may be redundant.
  3. For ensuring that the complete $PATH is available to scripts, GUI apps, etc., it appears to be a toss-up between launchd.conf and environment.plist... still researching that one.
3
  • 1
    I read just the other day (but I don't recall the source) that 10.8 no longer offers a surefire way to get a path visible to all apps. I remember in particular that environment.plist is no longer read; I am vaguely aware of launchd.conf, so that might work, but I think the article suggested it wouldn't. Commented Oct 2, 2012 at 23:41
  • 1
    more follow-up: it doesn't look like path_helper works at all in fish; it outputs either csh or bash syntax, both of which are incompatible. Instead, you can use ~/.config/fish/config.fish (the fish startup script) to cat /etc/paths.d/* and append them to $PATH. Hope that helps someone!
    – Chris4d
    Commented Feb 5, 2013 at 6:06
  • did you even read my answer? it's been there since four months before your follow-up
    – anddam
    Commented Feb 19, 2013 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .