MacOS Terminal – Understanding the Creation of $PATH in Bash and PHP Environment

bashmacospathPHPterminal

I am still relatively new to the workings of the Mac OS but have extensive knowledge of Linux. I updated my php on Mavericks using the php_osx and the instructions stated to use export PATH=/usr/local/php5/bin:$PATH to have the new php version used.

Through my attempt to update php I found references to the following files:

  • .bash_profile – I can not find this file.
  • .bashrc
  • paths
  • path_helper

Can someone please provide a simple understanding of how $PATH is created in Mavericks and help me understand where the export command put the edition to the path and how would I remove it if I want too?

Best Answer

On OS X you'll have following :

The base PATH used is located in /etc/paths. It is used to set $PATH.

By default, the file contains :

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

It will also load the paths located in /etc/path.d/.

When opening the terminal I will load :

  1. ~/.bash_profile
  2. ~/.bash_login, (if .bash_profile doesn't exist)
  3. ~/.profile (if .bash_login doesn't exist).

These files can load some other files, for example .bashrc.

If you want to expand your path you can do it in one of the files by adding your export command you gave in your question.