perlcpan

Where does CPAN install modules?


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.


Solution

  • First, some background. 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.

    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 the paths for all of these locations using the following:

    perl -V:'install.*'
    

    Those are the defaults use by the installers. However, the two most commonly used installers allow the user doing to installation to override any and all of these. In fact, it's common for people to unknowingly use local::lib to do so.

    If a module is installed in a non-standard location,