Home » Questions » Computers [ Ask a new question ]

Where does $PATH get set in OS X 10.6 Snow Leopard?

Where does $PATH get set in OS X 10.6 Snow Leopard?

I type echo $PATH on the command line and get

Asked by: Guest | Views: 106
Total answers/comments: 5
Guest [Entry]

"When bash starts it reads the following files every time you login. For the purposes of OS X, this means every time you open a new Terminal window.

/etc/profile
~/.bash_profile
~/.bash_login (if .bash_profile does not exist)
~/.profile (if .bash_login does not exist)

When you start a new shell by typing bash on the command line, it reads .bashrc

OS X also uses ~/.MacOSX/environment.plist to set more environment variables, including paths if necessary.

Finally, /etc/paths and /etc/paths.d are read by the shell too.

/opt/local/bin etc. are added in ~/.tcshrc by MacPorts. Also be sure to look in ~/.cshrc."
Guest [Entry]

"Seriously, Leopard gave us a new way to add path. Just create a file containing the path part you want to add, and put it in /etc/paths.d

A quick example of doing this in one step is:

echo ""/some/path/to/add"" >> /etc/paths.d/somefilename

Otherwise, you can just go to /etc/paths.d and put the file there directly. Either way, any path parts in the files in that directory will be appended to the default path.

This also works for manpath.

Here's a link to more details:

ars technica: how do i add something to PATH in snow leopard?

On a 2nd note: MacPorts puts everything into the opt directory precisely because it isn't used by Apple's stuff. That way it won't conflict. Their guide (excellently written, BTW) has an explanation of why it uses opt and how to change that default if you'd like.

MacPorts Guide"
Guest [Entry]

"It could be defined in either:

System variables - /etc/paths
User variables - see @Steve Folly's explanation"
Guest [Entry]

"Actually it is stored in your .profile file instead of .bash_login and it is common that MacPorts will use this instead of the .bash_login file.

Also The /opt directory is usually created by MacPorts and it stores its files in this folder."
Guest [Entry]

"Regarding docs for /usr/libexec/path_helper utility, initial components for $PATH was taken from /etc/paths and by default looks like

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

for OS-X Snow Leopard"