$PATH is driving me nuts
Solution 1
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:
-
path_helper
is called from/etc/profile
, by the syntaxeval '/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 myprofile
from loadingpath_helper
. Replaced the back-ticks and now it works like it should (of course). - 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 aspath_helper
works it may be redundant. - For ensuring that the complete
$PATH
is available to scripts, GUI apps, etc., it appears to be a toss-up betweenlaunchd.conf
andenvironment.plist
... still researching that one.
Solution 2
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
Solution 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!
Chris4d
Updated on September 18, 2022Comments
-
Chris4d over 1 year
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 expectHow 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!) usinghomebrew
and set it as my default shell (undersystem prefs>users & groups>advanced
). At some point, I ranbrew 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 ofgit
rather than the system copy. Fine - but betweenpath_helper
andfish
, 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, plusx11
,homebrew
, andfish
More info: I've set my user's default shell back to
bash
, and tried a variety of shells thruterminal.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 variousconfig.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 myprofile
and when I startterminal.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 likepath_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!
-
Admin over 11 yearsnote, I can get it to work for
fish
by creating~/.config/fish/config.fish
withset PATH /usr/local/bin $PATH
but I still have the issue ofpath_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 over 11 yearsThanks 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 forbash
, but I actually want it to work infish
(and consistently across the system, if that's not too much to expect). -
Aaron Miller over 11 yearsAh -- 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 --
-
echristopherson over 11 yearsI 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.
-
Chris4d over 11 yearsmore 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!
-
Nabil about 11 yearsdid you even read my answer? it's been there since four months before your follow-up
-
topskip almost 11 yearsGreat! 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