PATHS — what are current/latest best practices

I have seen many apparently “outdated/obsolete” recommendations around on best practices for setting up PATHS on macOS.

  1. Configure by adding “export PATH…” in user .profile?
  2. Edit etc/paths file to move /usr/local/bin above /usr/bin ?
  3. Add this to your .profile [[ :$PATH: == *:$HOME/bin:* ]] || PATH=$HOME/bin:$PATH and create symlinks in /usr/local/bin/ to homebrew-symlinks for individual executables that you want to load first? link here
    3b. Add paths for specific home-brew executables to the paths.d folder?

I understand it depends on environment, but there must be an official recommended practice for ways to handle every case?

I look in paths.d and see that home-brew is already setup.

1 Like

Homebrew’s recommendation has always been to add $HOMEBREW_PREFIX/bin to your ~/.<SHELL>_profile. As far as I know the recomendation is to prefix the path.
3 seems like a solution for people who don’t trust the homebrew executables or want to mix install methods.

1 Like

Thanks for this! I would appreciate your comments on the following.

I have this in my .bash_profile which I believe allows me to make all export entries in .bashrc

if [ -f "$HOME/.bashrc" ] ; then
    	source $HOME/.bashrc
    fi

At some point I read that I needed these entries in .bashrc for Homebrew:

export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"

I just realized today, with it set this way, I have duplicates in my path.

I use su admin from my user account when installing homebrew binaries, updating and upgrading. Since I am using homebrew from more than one account I would need to add $HOMEBREW_PREFIX/bin to both .bashrc files… correct?

Or, should I add $HOMEBREW_PREFIX/bin to paths.d so it’s system wide?

When creating an entry in paths.d I’ve read I need to use the index number and source. Not sure how to find the index number I believe source is just the name of the executable?

EDIT:
I failed to mention that in etc/paths.d I have a file called homebrew with this content /usr/local/homebrew/bin. I am not sure if that’s something that homebrew added or I did.

Homebrew never modifies the path so you added that file.
I’d personally keep the paths for users as a user setting but that’s just personal preference.

Thank you. I removed that path in etc/paths.d.

I do remember how they were added. It was to link the man pages for HB executables. Using this advice

I added $HOMEBREW_PREFIX/bin to .bashrc as you suggested and I get this in terminal when running source

admin$ source .bash_profile
-bash: /bin: is a directory
admin$ source .bashrc
-bash: /bin: is a directory

Homebrew itself suggests how to set the PATH when updating homebrew:

Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin.
Consider setting the PATH for example like so:
  echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

After adding export PATH="/usr/local/sbin:$PATH" to .bashrc and running brew update I get another warning which didn’t occur before:

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
  echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

This is how I ended up with the two additional path settings in .bashrc

Different than what you suggest their recommendation has always been. I am confused.

In homebrew docs it suggests there is no reason to add paths because homebrew installs into an existing path location.

In homebrew docs is says to run this command to help Mac apps find homebrew installed binaries.

Sorry, $HOMEBREW_PREFIX was a force of habit. In formulae that usually expands to /usr/local. Meaning the suggestion is to add /usr/local/bin.