23

I'm trying to create a Makefile for a small Perl utility I wrote, And I'm struggling to find out a way to find where to install my man page when make is run as a non-root user.

I'm currently parsing the output of manpath to find out the first path in the $HOME directory… and it almost work fine.

Paths I've found are ~/man and ~/share/man

The only problem is that if those directories don't exist in the first place, manpath doesn't output any of them.

Questions

  • Is there a portable way to find out where I should install the man pages in the user's $HOME directory?
  • If not, which one of them should be preferred?
slm
  • 369,824

3 Answers3

22

You can put the man pages in this directory:

$HOME/.local/share/man

Accessing directly

And then you can access them directly using man:

man $HOME/.local/share/man/manX/manpage.1.gz

$MANPATH

You can check what the $MANPATH is with the command manpath, or echo out the environment variable $MANPATH.

Examples

$ manpath
manpath: warning: $MANPATH set, ignoring /etc/man_db.conf
/home/saml/apps/perl5/perlbrew/perls/perl-5.14.0/man:/home/saml/.rvm/rubies/ruby-1.9.2-p180/share/man:/home/saml/.rvm/man:/usr/local/share/man:/usr/share/man:/usr/brlcad/share/man:/usr/man:/usr/brlcad/share/man:/usr/brlcad/share/man

$ echo $MANPATH /home/saml/apps/perl5/perlbrew/perls/perl-5.14.0/man:/home/saml/.rvm/rubies/ruby-1.9.2-p180/share/man:/home/saml/.rvm/man:/usr/local/share/man:/usr/share/man:/usr/brlcad/share/man:/usr/man:/usr/brlcad/share/man:/usr/brlcad/share/man

You can add things to the MANPATH temporarily:

MANPATH=$HOME/.local/share/man:$MANPATH

If you want to make this permanent then add a file in your /etc/profile.d/ directory called myman.bash with the above MANPATH= line in it. This will get picked up system wide for everyone. If you want it to be just for you, then add it to your $HOME/.bash_profile or $HOME/.bashrc.

References

slm
  • 369,824
  • 2
    To suppress manpath warnings about MANPATH being set, you can pass the -q option. – Joseph R. Sep 15 '13 at 14:46
  • 2
    Yes, I know that I can tell to man where to look. I'm looking for a generic, portable way for an generic installation (ie: where is man looking on a standard configuration) – Romuald Brunet Sep 17 '13 at 13:02
  • Do an echo $MANPATH and see what that shows. Those are good places to start looking, or use the manpath command as I showed in my answer. – slm Sep 17 '13 at 13:03
  • Where did you get information about $HOME/.local/share/man? I could not find any official source for that. – Yaroslav Nikitenko Jul 12 '22 at 19:19
  • 2
    @YaroslavNikitenko see here for more - https://unix.stackexchange.com/a/36874/7453. It's also mentioned here - https://www.freedesktop.org/software/systemd/man/file-hierarchy.html. – slm Jul 13 '22 at 02:30
2

I have installed a few apps that I compiled, with the respective configures set for installing in ${HOME}/usr/local.

I find now that I have directories

~/usr/local/share/man/man1
~/usr/local/share/man/man3
~/usr/local/share/man/man5

with manpages gnuplot.1, gnuplot-ja.1, python3.1, python3.5.1, libpng.3, libpngpf.3, zlib.3, png.5, so I guess (given my prefix) it is a pretty standard location for apps installed locally.

It is then a candidate location for the cases where one has to choose manually the local man directory.

Of course, one can add arbitrary paths (and should do it even in the usual just case mentioned) for man pages with

export MANPATH="$HOME/usr/local/share/man${MANPATH:+:${MANPATH}}"

(cf. The bullet-proof way of Appending/Prepending for handling colons : in PATH).

AdminBee
  • 22,803
1

Answer with desciption

I am running Cygwin on Windows 7. When I try

echo $MANPATH

I get nothing. Here is my portable way of finding where to put new man pages.

$ { find / -maxdepth 2 -type d -name "*man*" 3>&2 2>&1 1>&3 | \
grep -v 'Permission denied' >&3; } 3>&2 2>&1

(A note on that crazy command is at the bottom of this answer.)

You could simply replace / with ~. Another possibility is under the Another note section below.

On my machine, the find command returned:

 /etc/openwsman
 /lib/filemanager-actions
 /lib/gnome-commander
 /lib/help2man
 /lib/window-manager-settings
 /share/man
 /usr/man

To me, that meant there were two possibilities: /share/man and /usr/man.

I chose to use /usr/man, which you wouldn't, but I needed to do some more exploring.

$ ls -l /usr/man
total 0
drwxr-xr-x+ 1 me Users 0 April 31 17:13 man1

So, where I had the new man files in a doc/ sub-directory of my working directory, I used

$ cp -R doc/* /usr/man/man1

Now, I could get to my "manual" by typing

$ man my_new_executable

If you don't see a likely candidate, you can remove this part or change it, e.g. to -maxdepth 3, or 4, or 5, or however deep it takes to find what you need. When I did so with 3, I found two other candidates, /var/cache/man and usr/share/man , but I had already found a working solution, so I didn't mess with them.


Another note

I believe that /share/man/man1 or /var/cache/man would be available to non-root users, as you had requested. Please, correct me if I am wrong.


The promised note at the bottom

Note that I used the -maxdepth 2 option with find, because I figured that the man directory would be within two directories of the file system root, and I did not want to get too many extraneous directories that somehow had the substring man, as did /lib/gnome-comander.

The extra stuff around the find is there to suppress any Permission denied errors in case you don't have access to su or sudo. Here is a great description of what's happening. (Look for the line that starts with "gniourf_gniourf".)