简体   繁体   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. 我听说最好不要安装CPAN系统的Perl版本的模块。 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? 任何人都有他们成功使用的任何其他想法或实施?

I am using Arch Linux with Perl 5.16.2. 我正在使用Arch Linux和Perl 5.16.2。

Are you looking for something like local::lib 你在寻找像local::lib这样的东西吗?

local::lib - create and use a local lib/ for perl modules with PERL5LIB local :: lib - 使用PERL5LIB创建并使用本地lib / for perl模块

Download and extract the latest version of local::lib : 下载并解压缩local::lib的最新版本:

curl -LO http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008004.tar.gz
tar xzf local-lib-1.008004.tar.gz
cd local-lib-1.008004/

Deploy it: 部署它:

perl Makefile.PL --bootstrap=$HOME/perl5
make
make test
make install

Save persistent configuration: 保存持久配置:

cat << PROFILE >> $HOME/.profile

eval \$(perl -I\$HOME/perl5/lib/perl5/ -Mlocal::lib)
PROFILE

Now, you can logoff/logon your session or simply source ~/.profile . 现在,您可以注销/登录会话或只是source ~/.profile After that steps, CPAN modules will be installed locally. 完成此步骤后,将在本地安装CPAN模块。

You don't need to install the module manually. 您无需手动安装模块。 You just need to have somewhere to install it to, and your environment configured to install it there. 您只需要在某处安装它,并将您的环境配置为在那里安装它。 Then you can use cpan/cpanp/cpanm/etc as normal. 然后你可以正常使用cpan / cpanp / cpanm / etc。 (cpan minus wins for me) (cpan减去我的胜利)

Setting up that environment manually is a bit of a pain, so most people use an application to set up the configuration for them. 手动设置该环境有点麻烦,因此大多数人使用应用程序为它们设置配置。

The two main choices for this are: 这方面的两个主要选择是:

local::lib — This sets up your environment variables so you can install modules away from the system perl, but continues to use the system perl. local::lib - 这将设置环境变量,以便您可以远离系统perl安装模块,但继续使用系统perl。

Perlbrew — this installs a complete perl for you so lets you avoid your system perl entirely, and use a more up to date version of perl itself then might come with your system. Perlbrew - 这将为您安装一个完整的perl,因此可以让您完全避免使用perl系统,并使用更新的perl版本,然后可能随系统一起提供。 It also manages multiple perl installs side by side (so you can test your modules against different versions of perl). 它还可以并排管理多个perl安装(因此您可以针对不同版本的perl测试您的模块)。

Personally, I prefer Perlbrew (as it makes it easy to play with shiny new features like the yada yada operator and smart match (not that smart match is all that new now) but it takes longer to set up (as you have to compile perl). 就个人而言,我更喜欢Perlbrew(因为它可以很容易地玩yada yada运算符和智能匹配等闪亮的新功能(现在不是那么聪明的匹配)但是设置需要更长时间(因为你需要编译perl) )。

I have heard that it is best to not install modules from CPAN where your system's version of Perl is. 我听说最好不要安装CPAN系统的Perl版本的模块。

The idea is to avoid breaking your distro's tools by upgrading a module they use. 我们的想法是通过升级他们使用的模块来避免破坏您的发行版工具。

Installing the modules to a fresh directory and telling Perl about it using PERL5LIB (which is what aforementioned install::lib does) is not going to help at all in that case, since Perl sees exactly the same thing as if you had installed the module in the usual site directory. 将模块安装到一个新目录并使用PERL5LIB告诉Perl它(这就是前面提到的install :: lib所做的)在这种情况下根本没有帮助,因为Perl看到的东西与安装模块完全相同在通常的site目录中。

(One would mainly use PERL5LIB to install modules when one doesn't have permission to install to the default directories.) (当一个人没有安装到默认目录的权限时,主要使用PERL5LIB来安装模块。)

The other problem with using the system Perl is that you are prevented from upgrading it. 使用Perl系统的另一个问题是您无法升级它。

The solution to both is to install your own build of Perl. 两者的解决方案是安装自己的Perl构建。 This is very easy to do using perlbrew . 使用perlbrew非常容易。

What's about cpanminus? 什么是cpanminus? CPAN minus module CPAN减去模块

Why don't you pack the modules into real packages, rpm or dep style? 为什么不将模块打包成真正的包,rpm或dep风格? That way you keep control over the installed software, you can remove and update the packages as required and as you are used to. 这样您就可以控制已安装的软件,您可以根据需要随意删除和更新软件包。 So instead of bypassing the management, which rarely is a good idea, you stay in control. 所以,不要绕过管理,这很少是一个好主意,你保持控制。

If you are using an rpm based distribution I really recommend OBS for this task. 如果您使用的是基于rpm的发行版,我真的推荐OBS来完成这项任务。 You can create your own project, configure sources, test them and have packages created for all sorts of distributions and architectures. 您可以创建自己的项目,配置源代码,测试它们,并为各种分发和体系结构创建包。 And when you import your home projects repository into your software management then installing the packages comes down to a single click. 当您将家庭项目存储库导入软件管理时,只需单击一下即可安装软件包。

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

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