I installed rbenv through homebrew, and now I don’t know why path_helper put ~/.rbenv/shims at the end of the path instead of the beginning. And most importantly, how did path_helper get this information?
According to the man page of path_helper, it reads entries from /etc/paths and from files in /etc/paths.d. But I cannot find the string “.rbenv/shims” there.
~% cat /etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~% ls -la /etc/paths.d
total 0
drwxr-xr-x 2 root wheel 68 Jun 21 03:16 .
drwxr-xr-x 107 root wheel 3638 Sep 10 09:59 ..
~% /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/gordon/.rbenv/shims"; export PATH;
I suspect that your
.bash_profileor.bashrcis adding.rbenv/shimsto your PATH, and that is running at some point beforepath_helperis invoked during the shell start-up.The man page for path_helper opens with:
The crucial point here is that the path_helper utility is intended to
add contents to an existing
PATHsetting, not replace them. (And inactuality, what it really does is prepend contents, not append them,
which matters for
PATHvariables…)So, if I start out with an entry on my
PATH, the setting generated bypath_helper will ensure that entry continues on the
PATHit generates.Note that
foohas been included in my PATH in the last line, even thoughthe contents of
/etc/pathsand/etc/paths.d/*have not changed.At the same time, the path_helper utility also seems to be careful not
to produce paths with duplicate entries; it removes duplicate entries
after concatenating
/etc/pathsand/etc/paths.d/*and the currentPATH.This latter detail can be especially confusing since it can cause
entry reorderings compared to the original
PATHsetting (!).Below are some examples of this behavior: The first case shows a duplicate
foobeing removed. The second and third case illustrate entry reordering: the generated PATH is the same in both cases, but in the third case, the/usr/binentry has been moved from in-betweenfooandbarto the front of thePATH. (This duplicate-entry removal seems to be based on just simple string-matching on the pairs of entries, as illustrated by the fourth case below where the string/usr/bin/remains betweenfoo/andbar.)Finally, to give credit where credit is due:
While all of the command sequences above are the result of my own investigations, I was originally inspired to look into the behavior of
path_helperafter reading the note here,which pointed out that
path_helperreuses thePATHenvironment variable set by the parent process.