MacOS – What does adding PATH to .bashrc do

bashhomebrewmacosterminal

I'm following this guide to install Linux commands onto my OS Terminal: https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/ and I see that the second line tells me to add a line to my .bashrc file, which I have to create since I don't have one. Can anyone explain to me what this does? As well as the PATH command in general?

Best Answer

When you run a command in bash (or any other Unix shell), the shell searches for this command in a number of directories. The list of directories is stored in the variable called PATH, paths are separated by :.

The command in question extends the already defined $PATH by two additional paths:

  • /usr/local/bin which is the usual place user-provided commands get installed to
  • The output of $(brew --prefix coreutils)/libexec/gnubin which points to some utility commands required by brew

To see the current value of PATH, run echo $PATH in Terminal.