Feb 05

Mac OS X command and manual search path (PATH and MANPATH for man)

Mac OS X Leopard provides a simple way to manage your system-wide PATH and MANPATH for command and man pages.

On traditional UNIX and Linux, setting the PATH and MANPATH is usually done on a per-shell basis. For example, bash (the default Linux shell) usually has a sensible default configured in /etc/profile. This is often extended or overridden in each user's own .bash_profile (or .bashrc).

Mac OS X Leopard (I'm not sure if Tiger did this) provides a slightly different way to manage system-wide search paths. The /etc/profile is still there, but looks like this:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && . /etc/bashrc
fi

Note how the path_helper program is invoked.

This program does something very simple: it looks through the contents of /etc/paths.d (or /etc/manpaths.d for man pages) and prints a string to stdout containing all the paths in those files. For example, my /etc/paths.d looks like this:

hornet:~ root# ls -l /etc/paths.d/
total 16
-rw-r--r--  1 root  wheel  13 Sep 24 04:53 X11
-rw-r--r--  1 root  wheel  15 Feb  5 12:36 macports
hornet:paths.d root# cat X11
/usr/X11/bin
hornet:paths.d root# cat macports
/opt/local/bin

Running the paths_helper command yields (sorry for the long lines):

hornet:paths.d root# /usr/libexec/path_helper -s
PATH="/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin"; export PATH
MANPATH="/usr/share/man:/usr/local/share/man:/usr/X11/man"; export MANPATH

You can see that paths_helper has appended the contents of the files to the PATH and MANPATH.

So - to add paths to the global search path in Leopard, just drop a new file containing your path in /etc/paths.d.

See the man page for path_helper(8) for full details.

Comments

1 Walt Novinger says...

Your discussion helped point me in the right direction, but in OS X Snow Leopard it appears that things have changed (once again!). Here is what I found:

/etc/paths.d works as described. When /etc/libexec/path_helper is run, the PATH variable for the user's bash is, indeed, appended with the contents of the file(s) found in paths.d. This does not, however, affect the manner in which commands are searched for.

To make commands findable by bash, the name of the directory in which they are found must be added to /etc/paths. The contents of this file on my machine was: /usr/bin /bin /usr/sbin /sbin /usr/local/bin

I appended my private executables directory name to this file (using sudo vi /etc/paths) and all is well.

What is strange is that the which command finds my executables with just a simple PATH modification, but without tyhe /etc/paths modification, my bash shell will not find the executable.

Hope this helps folks.

Walt

Posted at 8:37 p.m. on January 19, 2010

I've disabled comments for now due to spam problems - I'll turn them back on when I've fixed it!

This won't be published anywhere, it's just in case I need to contact you.

You can use Markdown in your comments. Be sensible!

Sorry about this, but I don't want spam comments.