69

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?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Ram
  • 3,034
  • 11
  • 38
  • 46
  • 2
    In general, you should provide the error message. "Some error" doesn't help much. – jrockway Feb 12 '09 at 10:24
  • 5
    possible duplicate of [How can I use a new Perl module without install permissions?](http://stackoverflow.com/questions/251705/how-can-i-use-a-new-perl-module-without-install-permissions) – daxim Feb 03 '11 at 12:48
  • IMPORTANT.. some modules use Build.PL instead of Makefile.PL (or wrap it with one or the other), in some cases, (like when the tests run), installing from/to a path with spaces in it will confuse the MANIFEST and cause the test(s) to fail, usually this only happens when RELEASE_TESTING is set, so make sure it isn't on your machine. If there are MANIFEST errors like this then there is probably others lurking, stick with paths that have no whitespace (space, tab, unispace, etc) – osirisgothra Oct 27 '14 at 11:34

5 Answers5

71

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
Community
  • 1
  • 1
brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • 1
    I think you should add quotes: `o conf mbuild_arg '--install_base /mydir/perl'` – Amro Oct 18 '12 at 08:47
  • 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? – skaurus Aug 07 '13 at 09:31
  • 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. – brian d foy Aug 09 '13 at 21:31
  • I noticed that the perlfaq hadn't yet been fixed, so in the spirit of fixing bugs [in the docs](https://github.com/perlorg/perlweb/tree/master/docs/learn/faq) when one finds problems, I just created [a pull request](https://github.com/perlorg/perlweb/pull/146) to patch it. ;) – Trutane Jan 27 '15 at 20:51
  • @trutane: and patch my answer too if someone hasn't already done it! Get some StackOverflow activity with an edit! – brian d foy Jan 27 '15 at 21:00
  • unfortunately, I can't even start cpan - mkdir /scr/root/cpan: Permission denied – dbn Mar 03 '16 at 01:43
  • How to do same with `cpan` options? – Eugen Konkov Jun 27 '22 at 19:48
45

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
XenF
  • 584
  • 4
  • 4
  • 13
    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. – jrockway Feb 12 '09 at 20:27
  • 11
    use INSTALL_BASE instead of PREFIX. – brian d foy Feb 12 '09 at 23:06
  • 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 – Ram Apr 30 '09 at 10:06
  • 1
    "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." —— http://perldoc.perl.org/ExtUtils/MakeMaker.html#INSTALL_BASE – Lee Goddard Jul 17 '14 at 07:04
  • 3
    the INSTALL_BASE parameter isn't supported in Perl v5.8.8 (http://perldoc.perl.org/5.8.8/ExtUtils/MakeMaker.html), it showed up on v5.8.9 (http://perldoc.perl.org/5.8.9/ExtUtils/MakeMaker.html). – David I. Sep 11 '14 at 18:03
20

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.

jrockway
  • 42,082
  • 9
  • 61
  • 86
3

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.

hooverbag
  • 5
  • 2
tiktak
  • 1,214
  • 8
  • 15
3

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

perl Makefile.PL INSTALL_BASE=/mydir/perl
parthi
  • 156
  • 1
  • 8