CPAN doesn't actually install files. It runs the install script embedded in each distribution, which then performs the actual install.
For distributions using ExtUtils::MakeMaker, the defaults are documented here: https://metacpan.org/pod/ExtUtils::MakeMaker#make-install (and the default value of INSTALLDIRS
is site
). For Module::Build, see https://metacpan.org/pod/Module::Build#INSTALL-PATHS.
When the documentation talks about $Config{foo}
or %Config
, it means the %Config
variable provided by the Config module. The value of $Config{foo}
can also be inspected by running perl -V:foo
.
(If you think this seems unnecessarily complicated, you're right.)
The short version is that perl has multiple "system directories", one of which is for "site specific" modules and thus used as the default installation target. You are right that this is a single directory (per perl install), which doesn't mesh well with a multi-user system: It is shared across all users, and you need root permissions to install modules (and doing so might upgrade/override modules from system packages, which is a bad idea).
What people do instead is to configure ExtUtils::MakeMaker, Module::Build, etc to install into a user's home directory. This can be done with environment variables. Then they tell perl to add this directory to @INC
, so modules can actually be found and loaded. This is done with another environment variable, PERL5LIB
. (PERL5LIB
doesn't affect installation, it's purely used for loading.)
All of the above is automated and encapsulated in local::lib. (local::lib can also be used to e.g. create a per-project module subdirectory.)
The CPAN documentation also says:
As of CPAN 1.9463, if you do not have permission to write the default perl library directories, CPAN's configuration process will ask you whether you want to bootstrap local::lib
, which makes keeping a personal perl library directory easy.
You can sidestep the whole issue by installing a private perl in your home directory (in which case the "system" directory is just another subdirectory under your $HOME
and thus isn't shared with anyone and can be written to by you). This is very easy with e.g. perlbrew.
Another note: You've just found a bug in the documentation for PERL5LIB
. "and the current directory" is outdated: .
has been removed from the default list of module locations for security reasons.