Change your PATH environment variable in OS X

There are a few places where you can edit the PATH variable in OS X. There is the basic command that won’t last between sessions.

export PATH=/new/directory:$PATH

This one sets the PATH variable to ‘/new/directory’ plus everything that already was included in the PATH variable.

Furthermore, you can set the PATH variable to be accessible only to a certain login shell / user. To do this, you edit the .bash_profile file in the home folder of that user (~/.bash_profile). You then add above commando to the script.

Finally, you can set the PATH in an even wider scope, global, by editing the ~/.bashrc file. Once again, you just include above commando. Another approach to set your PATH in the global scope is by editing the /etc/paths file. In this file you just need to include the various directories seperated by a new line character. This approach can also be done more modular by adding your own files into the /private/etc/paths.d directory. The structure of the files is equal to the /etc/paths file, but they are all scanned, so you can split them up in logical files.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s