Paths and ManPaths in Leopard


Cool bit of info I picked up at Ars. We all know the standard way of modifying paths. In your .bash_profile you probably have a line like this:

export PATH=/opt/local/bin:/opt/local/sbin:$HOME/bin:$PATH:/usr/local/bin:/
export MANPATH=`/usr/bin/manpath`
export MANPATH=/opt/local/share/man:$MANPATH

Well apparently starting with Leopard and continuing with Snow Leopard there are two directories where you can put text files with paths in them and they’ll automatically be added to your PATH or MANPATH respectively.

So if you do

echo "/some/path" >> /etc/paths.d/PathFile

it will add that path to your PATH. (Obviously pick an informative name)

Likewise for MANPATH do

echo "/some/man/path" >> /etc/manpaths.d/PathFile

I honestly had never even heard of this. I’ll probably prefer to stick with editing my .bash_profile as I like to see everything at a glance and have absolute control over path ordering. But this is good to check from a security ore reliabiliyt point of view (to ensure some unwanted path isn’t present) Nothing’s worse than having something run unexpectedly because of an unexpected path or path order.

The program that handles these directories is

/usr/libexec/path_helper

You use the -c option if you are using a csh or csh compatible shell. For a Bourne shell use -s.

To see where it is called just open up /etc/profile.

Related posts:

  1. Upgrading to Snow Leopard Part 3: MacPorts
  2. Upgrading to Snow Leopard Part 4: MySQL
  3. Aliases and Symbolic Links
  1. #1 by Krishna on 2010/07/08 - 9:39 pm

    I know it’s going to almost be a year since you posted this, but thank you very much!!!

    I’m currently installing LaTeX on my machine and I wanted a way to access the manpages of custom packages I’m tucking away in ~/Library/texmf/

    With your hint, now I just execute

    sudo echo “~/Library/texmf/doc/man” >> /etc/manpaths.d/~texmf

    and it works great! Much cleaner than the $MANPATH method IMO.

  2. #2 by krimb1 on 2010/07/08 - 10:38 pm

    Correction, I discovered a few things:

    The command I listed above does not work because only the *echo* command receives sudo, but not the >>. Therefore I changed the command:

    echo “/Users/Krish/Library/texmf/doc/man” | sudo tee /etc/manpaths.d/~texmf

    That hint was thanks to http://ubuntuforums.org/showthread.php?t=766891

    Next, even with that correction, on 10.6.4 unfortunately that didn’t do the trick. I found out none of the files in manpaths.d were being loaded, and google found me on this Apple discussion page:

    http://discussions.apple.com/thread.jspa?threadID=2187861&start=15&tstart=0

    Turns out I needed to add the following line to my /etc/profile file:

    export MANPATH=

    After that, everything works!

Comments are closed.