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?

3 Answers 3

15

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.

4
  • 1
    That explains why I have been able to get away with prefixing /path: to $MANPATH even when it starts out empty.
    – muru
    Commented Nov 22, 2017 at 1:41
  • 2
    Better not set MANPATH: see answer about ~/.manpath below,
    – scrutari
    Commented Feb 24, 2021 at 22:16
  • 4
    @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. Commented Feb 27, 2021 at 0:21
  • To add to what Colin Watson wrote, you could add to the MANPATH environment variable different values inside different shells. Specializing each shell differently. For instance to be able to use different versions of a tool-chain inside each specialized shell and use the man directories related to the appropriate version. I don't think you can do that easily with the ~/.manpath file.
    – PRouleau
    Commented May 26 at 16:22
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.

2
  • Better not set MANPATH: see answer about ~/.manpath below,
    – scrutari
    Commented Feb 24, 2021 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
    Commented Feb 25, 2021 at 7:25
11

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
7
  • This is the correct answer: this way does not corrupt any global configuration, so it is the most safe one.
    – scrutari
    Commented Feb 24, 2021 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
    Commented Feb 25, 2021 at 7:22
  • @scrutari Setting an environment variable doesn't "corrupt any global configuration" either. Commented Feb 27, 2021 at 0:22
  • I don't see any mention of ~/.manpath in the MacOS man page for man. Is this GNU-specific feature? Commented Jan 7, 2022 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 :) Commented May 10, 2023 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .