Development environment configurations. http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/
We have three different methods.
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
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
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:
sudo nano /etc/paths
That’s it! To test it, in new terminal window, type:
echo $PATH
etc/paths.d/
folderWithin that folder you can add text files with one path per line. For example:
etc/paths.d/postgresapp
Where postgresapp is a file with the content:
/Applications/Postgres.app/Contents/Versions/latest/bin
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
/usr/bin/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