Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing CPAN modules without root

Tags:

perl

cpan

I followed this helpful tutorial to get Perl installed just for my user. I am sorry to link to an external site but I think reading this is the only way to understand how to answer the question.

Anywho, I am feeding defaults to the CPAN config - the .cpan and CPAN directories created via the tutorial - yet for some reason CPAN still wants to dig into /usr/lib/ - which it just can't get to - when I try to install a module. This was while installing DBD::CSV.

Here is the error message:

All tests successful (7 subtests UNEXPECTEDLY SUCCEEDED), 3 tests skipped.
Files=23, Tests=706,  3 wallclock secs ( 2.28 cusr +  0.54 csys =  2.82 CPU)
/usr/bin/make test -- OK
Running make install
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: Can't create '/perl5lib/lib/Bundle/DBD'
mkdir /perl5lib: Permission denied at /usr/lib/perl5/5.8.8/ExtUtils/Install.pm line 457
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
at -e line 1
make: *** [pure_site_install] Error 13
/usr/bin/make install  -- NOT OK

It seems to be going to the wrong perl5lib.

like image 760
PinkElephantsOnParade Avatar asked Jul 06 '12 18:07

PinkElephantsOnParade


People also ask

How do I install CPAN?

CPAN has evolved and the easiest way now to install CPAN modules is using the CPAN:App::cpanminus installer. It can be run with or without root privileges. (Generally running as root is not recommended.) When run as root it installs into the system libraries.

How install Perl modules Linux CPAN?

To install Perl modules using CPAN, you need to use the cpan command-line utility. You can either run cpan with arguments from the command-line interface, for example, to install a module (e.g Geo::IP) use the -i flag as shown.

Where do CPAN modules get installed?

CPAN doesn't actually install files. It runs the install script embedded in each distribution, which then performs the actual install. For distributions using ExtUtils::MakeMaker, the defaults are documented here: https://metacpan.org/pod/ExtUtils::MakeMaker#make-install (and the default value of INSTALLDIRS is site ).


3 Answers

Yeah, local::lib helps. I suggest using cpanm instead of cpan. I think it defaults to installing everything ~/perl5/lib/perl5. Here's a super useful tutorial.

like image 196
Jason Crowther Avatar answered Oct 19 '22 23:10

Jason Crowther


local::lib causes installers to use INSTALL_BASE, which I consider broken. I use perlbrew to install a local copy of Perl instead.

  • You don't mess with your system's install of Perl, so you don't break your operating environment.
  • Allows you to have multiple versions and builds of Perl installed with no hassle.
  • INSTALL_BASE need not be used.
  • No need for special permissions.
like image 27
ikegami Avatar answered Oct 19 '22 23:10

ikegami


take a look at this module: local::lib

like image 39
Miguel Prz Avatar answered Oct 20 '22 00:10

Miguel Prz