简体   繁体   中英

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?

I am using Arch Linux with Perl 5.16.2.

Are you looking for something like local::lib

local::lib - create and use a local lib/ for perl modules with PERL5LIB

Download and extract the latest version of 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 . After that steps, CPAN modules will be installed locally.

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 minus wins for me)

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.

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. It also manages multiple perl installs side by side (so you can test your modules against different versions of 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).

I have heard that it is best to not install modules from CPAN where your system's version of Perl is.

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.

(One would mainly use PERL5LIB to install modules when one doesn't have permission to install to the default directories.)

The other problem with using the system Perl is that you are prevented from upgrading it.

The solution to both is to install your own build of Perl. This is very easy to do using perlbrew .

What's about cpanminus? CPAN minus module

Why don't you pack the modules into real packages, rpm or dep style? 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. 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.

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