Does the page for a command get installed with it
Yes, it usually does but of course you can always add a new custom manpage to your system without using your local package management system. You can use your system package manager to learn what package a
given manpage com from. A big portion of manpages on Linux-based
systems comes from the Linux man-pages
project.
If it brings it from the network, then how secure is it?
It doesn't but as others said it's possible that someone has written their own implementation that does. I guess that your confusion might come from the first line in man man
that says:
man - an interface to the on-line reference manuals
Or in BSD version:
man — display online manual documentation pages
See this LQ
question
for an explanation.
For fun see also https://explainshell.com. It's a nice site that can
quickly explain meaning of options in a given command, for example
https://explainshell.com/explain?cmd=ls+-Alhtr but remember that your
local implementation of a given command may differ or may not support
all options (this is especially true when using small Busybox-like
based systems).
And of course man
can work via network in a sense that you can mount
a remote directory locally and tell man
to look for manpages there, for
example I can read manpages from the remote FreeBSD machine like that:
$ sshfs freebsd:/usr/share/man /mnt/bsd-manpages
$ MANPATH=/mnt/bsd-manpages man man
$ MAN(1)
BSD General Commands Manual MAN(1)
NAME
man — display online manual documentation pages
Does man cache the pages locally? If it does, should I clear it on a
regular basis?
Already well explained in telcoM's
answer.
man
are you using? POSIX explicitly doesn't state whereman
gets manpages from ("The historical MANPATH variable is not included in POSIX because no attempt is made to specify naming conventions for reference page files, nor even to mandate that they are files at all. On some implementations they could be a true database, a hypertext file, or even fixed strings within the man executable.") – muru Mar 27 '20 at 03:09