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

127,559

Solution 1

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

Solution 2

Other answers already on Stackoverflow:

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

Solution 3

local::lib will help you. It will convince "make install" (and "Build install") to install to a directory you can write to, and it will tell perl how to get at those modules.

In general, if you want to use a module that is in a blib/ directory, you want to say perl -Mblib ... where ... is how you would normally invoke your script.

Solution 4

I strongly recommend Perlbrew. It lets you run multiple versions of Perl, install packages, hack Perl internals if you want to, all regular user permissions.

Solution 5

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

perl Makefile.PL INSTALL_BASE=/mydir/perl
Share:
127,559
Ram
Author by

Ram

pro-g-Ram-er

Updated on July 08, 2022

Comments

  • Ram
    Ram almost 2 years

    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?

  • melo
    melo about 15 years
    I really recommend that you use local::lib. It takes care of all the little details.
  • jrockway
    jrockway about 15 years
    There is no reason to modify your script -- set PERL5LIB instead of using use lib. local::lib takes care of this for you -- follow its instructions and you should be fine.
  • Ram
    Ram about 15 years
    perl Makefile.PL INSTALL_BASE=/home/irraju/PadWalker gave me this error "'INSTALL_BASE' is not a known MakeMaker parameter name." Even PREFIX option gave me the same
  • Amro
    Amro over 11 years
    I think you should add quotes: o conf mbuild_arg '--install_base /mydir/perl'
  • reinierpost
    reinierpost about 11 years
    Unfortunately it fails to pass 'make test' when I try to install it.
  • skaurus
    skaurus almost 11 years
    Brian, one question - link you've provided tells that --install_base parameter is passed to perl Build.PL; but mbuild_arg is about arguments to ./Build. Maybe you mean mbuildpl_arg? Or there is error in perlfaq?
  • brian d foy
    brian d foy over 10 years
    I'm no longer maintaining the perlfaq, so you'll have to patch it through whatever that process is now. It looks like you are right though.
  • Lee Goddard
    Lee Goddard almost 10 years
    "INSTALL_BASE can be passed into Makefile.PL to change where your module will be installed. INSTALL_BASE is more like what everyone else calls "prefix" than PREFIX is." —— perldoc.perl.org/ExtUtils/MakeMaker.html#INSTALL_BASE
  • Robyn
    Robyn over 9 years
    the INSTALL_BASE parameter isn't supported in Perl v5.8.8 (perldoc.perl.org/5.8.8/ExtUtils/MakeMaker.html), it showed up on v5.8.9 (perldoc.perl.org/5.8.9/ExtUtils/MakeMaker.html).
  • Trutane
    Trutane over 9 years
    I noticed that the perlfaq hadn't yet been fixed, so in the spirit of fixing bugs in the docs when one finds problems, I just created a pull request to patch it. ;)
  • brian d foy
    brian d foy over 9 years
    @trutane: and patch my answer too if someone hasn't already done it! Get some StackOverflow activity with an edit!
  • dbn
    dbn about 8 years
    unfortunately, I can't even start cpan - mkdir /scr/root/cpan: Permission denied
  • ceving
    ceving over 7 years
    Is the link dead?
  • Eugen Konkov
    Eugen Konkov almost 2 years
    How to do same with cpan options?