I can't find an authoritative/comprehensive description of where CPAN installs its files. I assume there must be a set of rules and that it's not as simple as "XYZ directory" because, for example, multiple users on a Linux box can run CPAN even though there's a single Perl installation and it still somehow works. So, what are those rules?
A second part of this question: The documentation for the PERL5LIB environment variable says that it is "A list of directories in which to look for Perl library files before looking in the standard library and the current directory."
I assume that CPAN doesn't install into the standard library location, since presumably that is fixed for a particular Perl version. So maybe CPAN installs into PERL5LIB?
And finally, as I already alluded to, how does CPAN handle the fact that multiple users might be running the same Perl installation? Sorry if that's a separate question but it seems probably related.
You need to use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.
Available commands are: l - List all installed modules m - Select a module q - Quit the program cmd? Sample outputs: Installed modules are: JavaScript::SpiderMonkey Log::Log4perl Perl cmd?
To install Perl modules using CPAN, you need to use the cpan command-line utility. You can either run cpan with arguments from the command-line interface, for example, to install a module (e.g Geo::IP) use the -i flag as shown.
You'll find them in /usr/lib/perl/{VERSION}/ as well as /usr/lib64/perl/{VERSION}/ . {VERSION} corresponding to the version of Perl. You can get it with perl --version .
First of all, CPAN doesn't install modules. It's a repository.
cpan
doesn't install modules either. cpan
downloads distributions from CPAN and runs the installer provided within, be it Makefile.PL
or Build.PL
. (Same goes for cpanm
and cpanp
.)
These installation scripts mostly use ExtUtils::MakeMaker or Module::Build to install the distribution (though other installers exist).
Perl specifies three sets of installation locations.
perl
, for modules included with Perl itself.vendor
, for modules installed by the provider of your perl
binary.site
, for modules installed using cpan
.Each of these sets provides installation locations for a number of files types.
Installation location
--------------------------------------------------------
Type of file perl vendor site
---------------------- --------------- --------------------- -------------------
Build-specific modules installarchlib installvendorarch installsitearch
Modules installprivlib installvendorlib installsitelib
Binary programs installbin installvendorbin installsitebin
Other programs installscript installvendorscript installsitescript
man pages for scripts installman1dir installvendorman1dir installsiteman1dir
man pages for modules installman3dir installvendorman3dir installsiteman3dir
html docs for scripts installhtml1dir installvendorhtml1dir installsitehtml1dir
html docs for modules installhtml3dir installvendorhtml3dir installsitehtml3dir
You can obtain the path for any of these locations using the following:
perl -V:{var} # Substitute `{var}` for the var name.
You can obtain all the paths for these locations using the following:
perl -V:'install.*'
Those are the defaults use by the installers[1]. However, the two most commonly used installers allow the user doing to installation to override any and all of these. If a module is installed in a non-standard location,
PERL5LIB
can be used to let perl
know where to find the modules.PATH
can be used to let the system know where to find bundled programs.MANPATH
can be used to let man
know where to find the man pages.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With