Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install a CPAN module into a local directory?

I'm using a hosted Linux machine so I don't have permissions to write into the /usr/lib directory.

When I try to install a CPAN module by doing the usual:

perl Makefile.PL make test make install 

That module is extracted to a blib/lib/ folder. I have kept use blib/lib/ModuleName but it still the compiler says module can not be found. I have tried copying the .pm file into local directory and kept require ModuleName but still it gives me some error.

How can I install a module into some other directory and use it?

like image 525
Ram Avatar asked Feb 12 '09 09:02

Ram


People also ask

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 ).

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.


2 Answers

Other answers already on Stackoverflow:

  • How do I install modules locally without root access...
  • How can I use a new Perl module without install permissions?

From perlfaq8:


How do I keep my own module/library directory?

When you build modules, tell Perl where to install the modules.

For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:

perl Makefile.PL INSTALL_BASE=/mydir/perl 

You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell:

% cpan cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl cpan> o conf commit 

For Build.PL-based distributions, use the --install_base option:

perl Build.PL --install_base /mydir/perl 

You can configure CPAN.pm to automatically use this option too:

% cpan cpan> o conf mbuildpl_arg '--install_base /mydir/perl' cpan> o conf commit 
like image 138
brian d foy Avatar answered Nov 12 '22 01:11

brian d foy


I had a similar problem, where I couldn't even install local::lib

I created an installer that installed the module somewhere relative to the .pl files

The install goes like:

perl Makefile.PL PREFIX=./modulos make make install 

Then, in the .pl file that requires the module, which is in ./

use lib qw(./modulos/share/perl/5.8.8/); # You may need to change this path use module::name; 

The rest of the files (makefile.pl, module.pm, etc) require no changes.

You can call the .pl file with just

perl file.pl 
like image 23
XenF Avatar answered Nov 12 '22 02:11

XenF