7/1/2015 - 1:22 PM

Development environment configurations. http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/

Add to the PATH on Mac OS X

We have three different methods.

Edit ~/.bash_profile

The ~/.bash_profile is executed every time we log into the system. It's read by bash only (the ~/.profile file should be used in other cases; if the system has a bash_profile and we start a bash shell it will read bash_profile instead profile).

In this case, to add a new path we should add the following line at the end of the ~/.bash_profile file:

PATH = $PATH:/my/custom/path

Add a symbolic link

We can add a symbolic link on /usr/local/bin (which is included by default on OS X):

ln -s /my/custom/path /usr/local/bin

Edit /etc/paths (less recommendable)

There is a very neat way to add the .../bin directory of an installed app in OS X to the path, the /etc/paths file. The file contains a list (one per line) of paths that are added to the $PATH variable in the shell. Here are some quick directions to add to the path:

  • Open up Terminal.
  • Run the following command:
sudo nano /etc/paths
  • Enter your password, when prompted.
  • Go to the bottom of the file, and enter the path you wish to add.
  • Hit control-x to quit.
  • Enter “Y” to save the modified buffer.

That’s it! To test it, in new terminal window, type:

echo $PATH

Use etc/paths.d/ folder

Within that folder you can add text files with one path per line. For example:


Where postgresapp is a file with the content:


Locate a program file in the user's path

Sometimes it could be useful to know which program are we using (in the case we have different versions installed). The programs are used depending on their directory and how is that directory added in the PATH.

For example, if we have two different versions of git, one from Apple and other installed with brew. We can know which one we're using by calling:

git --version
  git version 1.9.5 (Apple Git-50.3)
which git

The version installed by brew will be symlinked on /usr/local/bin so we should modify the bash_profile file to state that we'd like to use the programs there before /usr/bin/. We add the line:

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