I’ve recently being doing a cleanup of my dotfiles (more on that later). In the process I commented out all of the “
export PATH=...” statements in the
rc files in my home directory, but my path was still getting set to this:
There are three problems with this:
- I’d prefer my
/usr/local/binto be first
- I don’t want/need either of those git/x11 paths
- I don’t like not understanding where things are getting set!
I eventually worked out that it came down to some files in my
/etc directory :
#/etc/paths /bin /usr/bin /sbin /usr/sbin /usr/local/bin
paths.d method actually makes a lot of sense for a certain kind of application: it’s a nice clean way of adding bin files to the path nice and early (before any local modifications to the path).
Here’s the full order in which my paths were getting loaded in (I’m using zshell):
/etc/profile /etc/profile.d/* ~/.zshrc (which loads in ~/.profile)
/etc/profile can come into play as well, but mine doesn’t set the path so I’m not sure what the ordering is. Indeed it looks like /etc can have it’s own set of shell-specific configs as well (mine seems to have a default bashrc), but that’s a whole other ballgame.
Now that I properly understand how my path is getting generated, I’m comfortable setting it from scratch in my local profile:
#~/.profile export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin
I prefer to have
/usr/local/bin first, because this means that I can install things in
/usr/local and symlink them into
/usr/local/bin without conflicting with any old versions which came bundled with the operating system (and thus live in
I could have achieved the same effect by editing
/etc/paths, but I’d like to try and make my dotfiles as portable as possible
The following posts really helped me understand all this: