Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Installing modules locally

by szabgab (Priest)
on Jul 27, 2006 at 11:38 UTC ( #564029=perlquestion: print w/replies, xml ) Need Help??
szabgab has asked for the wisdom of the Perl Monks concerning the following question:

In some cases I need to install modules locally - that is not as root. I use
Makefile.PL PREFIX=/home/gabor/perl5lib
and I know I will somehow have to add this directory to @INC. As I would like to use these local installation in all of my modules I decided to add the path to PERL5LIB. The problem is that it seems various modules will install themself in diferent subdirectories. So now I have the following directories in PERL5LIB:
export P5=/home/gabor/perl5lib export PERL5LIB=$P5/share/perl export PERL5LIB=$PERL5LIB:$P5/lib/perl export PERL5LIB=$PERL5LIB:$P5/share/perl/5.8 export PERL5LIB=$PERL5LIB:$P5/usr/local/share/perl/5.8.7 export PERL5LIB=$PERL5LIB:$P5/lib/perl/5.8 export PERL5LIB=$PERL5LIB:$P5/usr/local/lib/perl/5.8.7
and I fully expect that I'll have to add even more directories as I install more modules. Is there an easier way to declare all these directories?

Replies are listed 'Best First'.
Re: Installing modules locally
by tinita (Parson) on Jul 27, 2006 at 12:31 UTC
    Makefile.PL PREFIX=/home/gabor/perl5lib
    just use:
    Makefile.PL PREFIX=/home/gabor/perl5lib LIB=/home/gabor/perl5lib

    At least this has been working well for me. All modules are now installed in the given directory instead of architecture-dependant ones and such and in the architecture dependant ones.
    I am using this also in cgipan.

    update: architecture-dependant directories are still used, but that's no problem for use lib. thanks to rinceWind for pointing that out.

      I agree with that approach. Specifying both LIB and PREFIX works very well for me. I use install_base for Module::Build and anything that insists on it.

      All modules are now installed in the given directory instead of architecture-dependant ones and such.

      That's not strictly true. Pure perl modules will be installed generically to the lib directory. Modules containing XS (or Inline::C, swig, etc.) are still installed into architecture dependent paths, but this is what you want. Indeed, you can share the lib tree across platforms - I do this between Solaris and Windows, and it works too!


      Oh Lord, won’t you burn me a Knoppix CD ?
      My friends all rate Windows, I must disagree.
      Your powers of persuasion will set them all free,
      So oh Lord, won’t you burn me a Knoppix CD ?
      (Missquoting Janis Joplin)

      Oh, that seems like the good solution. I'll go and try it. I have about 400 modules installed already so I will wait a bit till all that comes back to my private perl5lib directory.

      I hope it will also work with Module::Build.....

Re: Installing modules locally
by Hue-Bond (Priest) on Jul 27, 2006 at 11:53 UTC

    I have this problem too, and asked about it in Modules installation path. I'm using some bash to export the variable:

    function P5L { unset PERL5LIB; DIRS=(~/lang/perl/modules/{lib,share}/perl/*); local IFS=":"; export PERL5LIB="${DIRS[*]}"; ## double quoted array expansio +n indexed by "*" } && P5L

    Recently I've had to make an addition because Devel::Caller installed itself in another place:


    David Serrano

Re: Installing modules locally
by holli (Monsignor) on Jul 27, 2006 at 11:56 UTC
    Once the module is installed you could safely copy the module files to a single directory, eg. /perl/mymodules. That would also avoid version confusion. Imagine you install Foo::Bar 0.1 in /lib/Perl and Foo::Bar 0.2 in /usr/local/lib/perl/5.8.7. Perl would always load the version that is first in your perl path.

    holli, /regexed monk/
Re: Installing modules locally
by Hofmator (Curate) on Jul 27, 2006 at 12:29 UTC
    I might be wrong on this, but doesn't
    perl Makefile.PL LIB=/home/gabor/perl5lib
    specify exactly this installation path? As far as I know, the module is then installed into this exact path, meaning Module Foo::Bar ends up installed as /home/gabor/perl5lib/Foo/

    Update: Possibly you will have to specify PREFIX=/home/gabor/perl5lib or other such parameters like INSTALLSCRIPT, INSTALLBIN, INSTALLMAN3DIR as well, depending where you want these files to end up in

    -- Hofmator

Re: Installing modules locally
by rinceWind (Monsignor) on Jul 27, 2006 at 12:36 UTC

    I don't think you need all the system perl paths in PERL5LIB. The command perl -V will list out everything that is in @INC including all the paths that were set at perl's build time (in

    Of course, you might be trying to have more than one perl on your host, and trying to share some of the library directories. I would seriously advise against that, as there could be all sorts of unforseen side effects when you come to automatically install some modules to one of the perls, see A problem with two perls on a Debian system for when I came unstuck with this.

    My suggestion is to keep just the user install directories, e.g. /home/gabor/perl5lib in PERL5LIB. I've had no problems with this approach. I am in a work situation where I am installing modules to a place that doesn't require root. It's actually a Clearcase vob, but that's another story.


    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: Installing modules locally
by aspeer (Initiate) on Jul 29, 2006 at 06:10 UTC
    I had this problem when installing modules locally also. I wrote a small 'helper' module that I include from the command line, or in my scripts, which customises @INC for me by reading in a config file that contains a list of all directories I want added.

    The module looks for a file /etc/ (or %windir%/ and reads in a array ref of directories from that file.

    It then massages @INC to include all relevant directories under those paths using hints from about sitelib/privlib/archlib/vendorlib etc. without them needing to be explicitly declared.

    You can download the file from here - it is too hackish to upload to CPAN as a module.

    The /etc/ file is in Data::Dumper format - it looks like this:

    $VAR1=[ '/opt/project1', '/opt/project2', .. ];

    Then to include all the above directories *and* any relevant vendorlib/sitelib/archlib etc directories under them in which modules may have been installed, run

    perl -I/path/to/ -Mperl5lib

    Or include in your script:

    #!/bin/perl use lib '/path/to/', use perl5lib

    I did not know about the perl Makefile.PL PREFIX=<path> LIB=<path> option mentioned above though - that looks like a better idea if the modules are not already installed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://564029]
Approved by Hue-Bond
Front-paged by Courage
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2017-02-22 02:59 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (324 votes). Check out past polls.