How to set MANPATH without overriding defaults?

If you simply set MANPATH, it overrides the default and you lose access to the standard man pages. For example, man ls works before setting MANPATH, but does not work afterwards.

To append a search directory without overriding the default, prefix a colon to MANPATH like this:

export MANPATH=":/path/to/custom/man"

Adding the colon gives you access to both the standard system man pages and the custom pages referenced in the MANPATH variable.

This answer brought to you by manpath(1):

If $MANPATH is set, manpath displays its value rather than determining it on the fly. If $MANPATH is prefixed by a colon, then the value of the variable is appended to the list determined from the content of the configuration files. If the colon comes at the end of the value in the variable, then the determined list is appended to the content of the variable. If the value of the variable contains a double colon (::), then the determined list is inserted in the middle of the value, between the two colons.


You should add your custom directories at the end of your PATH:

PATH=$PATH:/my/dirs

This is so your custom directories do not override system binaries and libraries, which could cause a security issue.

You set MANPATH the same way (MANPATH is empty by default):

MANPATH=$MANPATH:/my/dirs

You should not need to set a MANPATH with well behaved packages, so if it is not broken don't fix it. If it is broken, perhaps you are better filing a bug report ;)

Add this to ~/.bashrc:

export PATH=$PATH:/my/dirs
export MANPATH=$MANPATH:/my/dirs

Tags:

Command Line