简体   繁体   English

安装CPAN模块而不会影响系统Perl的安装

[英]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. 我听说最好不要从系统版本的Perl所在的CPAN安装模块。 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. 我知道如何使用命令行安装模块,我只是想知道是否存在一种使CPAN与系统核心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). CPAN始终与核心分开–注意/usr/lib/perl5具有子目录core_perlvendor_perl (发行版打包的CPAN模块)和site_perl (本地安装的模块)。

Both ExtUtils::MakeMaker and Module::Build default to installing everything to the "site" directory; ExtUtils :: MakeMakerModule :: Build都默认将所有内容都安装到“ site”目录中。 this also applies to everything you install using the cpan or cpanm commands. 这也适用于使用cpancpanm命令安装的cpan cpanm If you use your Linux distro's packages, they go to the "vendor" path. 如果您使用Linux发行版的软件包,则转到“供应商”路径。

You can specify a different installation location (for example, to keep all CPAN modules in your home directlry) using: 您可以使用以下方法指定其他安装位置(例如,将所有CPAN模块保留在家庭目录中):

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. 当您安装在系统目录中时,所冒的风险是每个与系统相关的Perl脚本都将使用这些模块。 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. 建议在专用目录中安装的方法是使用local :: lib。 See the bootstrapping technique: https://metacpan.org/module/local::lib 请参阅引导技术: https ://metacpan.org/module/local:: lib

Once you set up local::lib you can use any of the standard CPAN clients to install modules. 一旦设置了local :: lib,就可以使用任何标准CPAN客户端来安装模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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