Browsing articles tagged with " export path"

Updating Your Export Path in OS X

Jun 28, 2010   //   by the guru   //   Mac  //  4 Comments

Seems like a simple one doesn’t it! I thought, so until I tried Googling it. I thought I would post a brief article about how to do this and explain how to use the Mac profile.

Firstly lets explain what the export path is. In simple terms the path is an environment variable called $PATH. The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

To see what your current $PATH variable is, enter the following in your terminal:

echo $PATH

So, how do we add to this. Well the variable is updated through the profiles stored on your Mac. The default profile is stored in the /etc folder and is loaded for all users. To edit this enter the following in terminal:

vi /etc/profile

In some cases you may want to add to the path just for a user. In this case you need to use the users profile by entering (you need to be logged in as them):

vi ~/.profile

If you do not have a profile setup, the vi command will add one to your system by opening a new file. For more information and a basic guide on how to use vi visit my “How to Use vi and Learn Some Basic vi Commands”.

If you don’t like using vi or have no idea you can use your default text editor and open the file by entering the following in terminal:

open .profile

So, how do we add to the export path then? Well if you want to replace the path with your own directories you simply enter:

export PATH=/directory_1:/directory_2

Note how each directory location is separated by a “:”.

For example:

export PATH=/opt/local/bin:/opt/local/sbin

It is important to note that a local user profile for a user will override the default path variable if you set it to your own paths. This is not always good. Especially if you have other apps using the path variable. In this case you don’t want to overwrite them when your machine loads. To get around this we just append to the path. To do this we enter:

export PATH=/directory_1:/directory_2:$PATH

or

export PATH=$PATH:/directory_1:/directory_2

Don’t forget the paths run in order of priority, so the paths that come first are used first. This is why you can append before or after the current path as showed above. A real-life example may look like:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Well I hope that clears up some confusion. It may just have been me, but there we go. Comment me with any questions or suggestions.