19

If the MANPATH environment variable is set, man very "helpfully" ignores the default search path, as defined in /etc/manpath.config. Is there any way add a path or paths to that searched by man?

mjs
  • 309
  • 1
  • 2
  • 7

3 Answers3

12

It depends on the man implementation, but since you have /etc/manpath.config I'm guessing that you're using a Debian-derived system with man-db.

In that case, manpath(1) describes what you can do here (and the same approach will work for man(1)):

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.

muru
  • 72,889
Colin Watson
  • 3,640
  • 1
    That explains why I have been able to get away with prefixing /path: to $MANPATH even when it starts out empty. – muru Nov 22 '17 at 01:41
  • 2
    Better not set MANPATH: see answer about ~/.manpath below, – scrutari Feb 24 '21 at 22:16
  • 3
    @scrutari I mean, I'm the maintainer of man-db :-) It's true that ~/.manpath is more flexible, but it's also that bit more complex to configure as a result of that flexibility, as compared with MANPATH which has obvious analogies with PATH. If all you need is to adjust the search path then I think it's perfectly reasonable to use the environment variable approach. – Colin Watson Feb 27 '21 at 00:21
11

Depending on the particular implementation of man, you may augment the value of MANPATH in different ways.

On Linux systems, set MANPATH to the value of manpath -g:

export MANPATH="$(manpath -g):/new/path/man"

or create an alias like

alias man='man -M "$(manpath -g):/new/path/man"'

On FreeBSD, do as above, but drop the -g.

On OpenBSD and NetBSD, use

alias man='man -m /new/path/man'

Consult the manual for the man utility on your Unix.

Kusalananda
  • 333,661
  • Better not set MANPATH: see answer about ~/.manpath below, – scrutari Feb 24 '21 at 22:15
  • @scrutari There is no indication in your comment how this applies to my answer. Comments are primarily for suggesting improvements to answers, but you should also be able to improve by suggesting edits directly. – Kusalananda Feb 25 '21 at 07:25
8

Don't set MANPATH env variable.

You can add any number of custom paths to your local ~/.manpath file:

MANDATORY_MANPATH /usr/local/texlive/2020/texmf-dist/doc/man

That is for a TeXlive distribution installed on /usr/local/texlive. This file can have any number of such entries.

Also, if you have some custom /path/to/some/bin on your PATH, where /path/to/some/bin/.. has any of these subdirectories man, bin/man, share/man, or share/man, this man path will be added automatically (unless you prevent it by setting the MANPATH env variable).

You can check how paths are picked up by man by running

manpath -d
scrutari
  • 174
  • This is the correct answer: this way does not corrupt any global configuration, so it is the most safe one. – scrutari Feb 24 '21 at 22:09
  • 2
    @scrutari Unfortunately, this answer does not say what Unix this applies to. Note that the question does not specify explicitly what Unix they are using. Also note that the environment variable MANPATH is modifiable per user, just like any environment variable, and just like the ~/.manpath file. – Kusalananda Feb 25 '21 at 07:22
  • @scrutari Setting an environment variable doesn't "corrupt any global configuration" either. – Colin Watson Feb 27 '21 at 00:22
  • I don't see any mention of ~/.manpath in the MacOS man page for man. Is this GNU-specific feature? – shadowtalker Jan 07 '22 at 15:53
  • I can confirm that the ~/.manpath approach works under Bluehost's CentOS 7 (I believe that's what they're running) in shared hosting. Well done :) – Gwyneth Llewelyn May 10 '23 at 09:43
  • Grr... Why doesn't man manpath contain this detail? (man man mentions it, though) – Jesse Adelman Aug 23 '23 at 20:16
  • This (~/.manpath) doesn't work for my Raspberry Pi or Debian systems. – Seamus Dec 19 '23 at 02:06