简体   繁体   中英

Install CPAN Modules without messing up the system Perl installation

I have heard that it is best to not install modules from CPAN where your system's version of Perl is. I know how to install modules using the command line, I was just wondering if there is a way to keep CPAN separate from the system's core Perl.

Should I:

Download the source and make a directory specifically for these modules?

Anybody have any other ideas or implementations they have used successfully?

CPAN is always separate from core – notice how /usr/lib/perl5 has subdirectories core_perl , vendor_perl (CPAN modules packaged by the distro) and site_perl (modules installed locally).

Both ExtUtils::MakeMaker and Module::Build default to installing everything to the "site" directory; this also applies to everything you install using the cpan or cpanm commands. If you use your Linux distro's packages, they go to the "vendor" path.

You can specify a different installation location (for example, to keep all CPAN modules in your home directlry) using:

dir=~/perl5

export PERL5LIB="${dir}"
export PERL_MM_OPT="INSTALL_BASE='${dir}'"
export PERL_MB_OPT="--install-base '${dir}'"

The risk you take when you install in the system directories is that every system related Perl script will use those modules. If one of the modules is a newer and incompatible version of a module the system uses, then you won't be happy.

The recommended way to install in a private directory is to use local::lib. See the bootstrapping technique: https://metacpan.org/module/local::lib

Once you set up local::lib you can use any of the standard CPAN clients to install modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM