Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Personal library with CPAN

by yoda54 (Monk)
on Jun 07, 2004 at 05:42 UTC ( #361886=perlquestion: print w/ replies, xml ) Need Help??
yoda54 has asked for the wisdom of the Perl Monks concerning the following question:

I've missed this somewhere. How does one use CPAN to install modules in a personal directory? When I run a "perl -MCPAN -e shell" it always errors out because I have no root access. I've downloaded CPAN and have installed it to my home but what is next? Thanks much!

Comment on Personal library with CPAN
Re: Personal library with CPAN
by Zaxo (Archbishop) on Jun 07, 2004 at 05:55 UTC

    Copy the system CPAN::Config module to ~/.cpan/CPAN/MyConfig.pm and edit it to provide your own build paths and make directives, particularly the installation prefix directory.

    You will probably want to set up the PERL5LIB environment variable to let perl find your private installations.

    Update: Some adaptation of this sequence of commands will set you up (tested):

    $ mkdir ~/.cpan $ mkdir ~/.cpan/CPAN $ cd ~/.cpan/CPAN $ cp /usr/lib/perl5/5.8.4/CPAN/Config.pm MyConfig.pm $ perl -pi -e's!/root/\.cpan!$ENV{HOME}/.cpan!' MyConfig.pm $ perl -pi -e'/makepl_arg/ && s!\]! PREFIX=$ENV{HOME}]!' MyConfig.pm $ echo "export PERL5LIB=${HOME}/lib/perl5/site_perl/5.8.4/i686-linux:$ +{HOME}/lib/perl5/site_perl/5.8.4" >> ~/.bash_profile $ . ~/.bash_profile $ perl -MCPAN -e shell
    That should be all you need to do, as long as the system CPAN setup is similar enough and your shell bash enough.

    After Compline,
    Zaxo

      How do you know this?

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        It's in the, uhhh.., Pod ;-). perldoc CPAN, way down in the "Configuration" section, around page 14 on this terminal.

        After Compline,
        Zaxo

      Hi Zaxo,
      The lists of command you provided works great. The really nice things about that set-up is that:

      1. You can call the module without having to invoke the standard "use lib" command.
      2. You can call the perldoc of the modules installed locally from anywhere.

      All these happen JUST as it was installed internally as ROOT! It's incredible.
      Would you mind explain which part of the command above that does that? I can somehow guess, but not sure.
      Regards,
      Edward

        Line seven sets and exports the environment variable PERL5LIB in the bash login shell configuration. That is the part which tells Perl where else to look for modules. Technically, Perl adds the path in $PERL5LIB to @INC. The perlrun and perlvar docs tell all.

        The following line sources ~/.bash_profile in the current shell so that Perl has the benefit of PERL5LIB right away. That amounts to rereading the shell config.

        That may fail to influence a web server's Perl environment. If it does, you can use the SetEnv directive in .htaccess or the server configuration for regular cgi scripts. I think PerlSetEnv should work for mod_perl, but mod_perl usually implies enough control that a private perl lib is unnecessary, so I've never tried that setup.

        After Compline,
        Zaxo

      That seems to work great. But then while installing DBI it dies with the following error

      /usr/local/bin/perl -p -e "s/~DRIVER~/Perl/g" ./Driver.xst > Perl.xsi /usr/local/bin/perl /usr/local/lib/perl5/5.8.0/ExtUtils/xsubpp -typem +ap /usr/local/lib/perl5/5.8.0/ExtUtils/typemap -typemap typemap Perl +.xs > Perl.xsc && mv Perl.xsc Perl.c cc -c -DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN" -DHAS_FPSET +MASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include +-O -pipe -DVERSION=\"1.50\" -DXS_VERSION=\"1.50\" -DPIC -fPIC "-I +/usr/local/lib/perl5/5.8.0/mach/CORE" -W -Wall -Wpointer-arith -Wbad +-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual -DDBI_NO +_THREADS Perl.c cc: permission denied *** Error code 126 Stop in /usr/home/sites/www.whereever.com/whereever/.cpan/build/DBI-1. +50. /usr/bin/make -- NOT OK Running make test Can't test without successful make Running make install make had returned bad status, install seems impossible
      I'll continue to search perlmonks, but i think this might just be a permission setting that is obvious to real unix hackers ;)


      ___________
      Eric Hodges

        Yes, that appears to be a permission problem with -DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.0/BSDPAN". If you need a private cpan directory, you probably don't have write permission there.

        I don't know if this is the source of the problem, but sometimes authors hardcode paths that they should let CPAN.pm figure out. You could try setting and exporting APPLIB_EXP before the build as a workaround.

        After Compline,
        Zaxo

      Dear Zaxo,
      I had my CPAN installation setting following your ingenious solution above.
      I never has compilation problem beforehand when running a Perl script (*.pl).

      Recently, while trying a CGI script like below (let's call it 'test.cgi'). I had problem compiling it.
      #!/usr/bin/perl -w use CGI ':standard'; use Mail::Sendmail;
      Although Mail::Sendmail is successfuly installed, my CGI script can't recognize the location. I encounter this strange result.

      When I run this:
      $ perl -c test.cgi # it gives test.cgi syntax OK
      But when I run this with taint:
      $ perl -cT test.cgi It gives: Can't locate Mail/Sendmail.pm in @INC (@INC contains: ~/lib/perl5/site +_perl/5.8.5/ /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/pe +rl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr +/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/sit +e_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i +386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thre +ad-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/ +lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/per +l5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site +_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl / +usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl +5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_per +l/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386 +-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-threa +d-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr +/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/li +b/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/p +erl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl +5/vendor_perl) at temp.cgi line 4. BEGIN failed--compilation aborted at temp.cgi line 4.
      How can I have my cgi script recognize the location of the library? I also tried using "use lib" construct like this:



      but also gives the same symptom.
      Does it has anything to do to the way I install the module following your approach?

      Update:
      That may fail to influence a web server's Perl environment. If it does, you can use the SetEnv directive in .htaccess or the server configuration for regular cgi scripts.
      Just realized you mentioned about the problem above. But how do you actually "SentEnv directive of server config" in my cgi scripts?

      Regards,
      Edward

        In a .htaccess file, put

        SetEnv PERL5LIB /where/the/mods/are/:/where/else/lib
        The web server must be able to read files in those directories, of course. Apache suExec is a great help with that, for security's sake.

        See the apache httpd manual for variations that might be handy. When mod_perl is involved, I believe PerlSetEnv is needed, but I've never tried that.

        After Compline,
        Zaxo

      With a modern version of CPAN you can use the command mkmyconfig in the CPAN shell. This will create your own ~/.cpan/CPAN/MyConfig.pm
        Since which version of CPAN?

        Regards,
        Edward
      I just noticed that with the last two releases of ExtUtils::MakeMaker, it looks like INSTALL_BASE is now preferred usage, and --install-base is preferred for Module::Build. (See the latest ExtUtils::MakeMaker::FAQ.) If so, your PERL5LIB will change slightly as will the buildpl_arg in MyConfig.pm.
      Dear Zaxo,
      How can I make your setting above workable in Mac OSX? Have you ever try it? I can't seem to find proper "Config.pm" in / This is all I have.
      ./System/Library/Perl/5.8.8/darwin-thread-multi-2level/Config.pm ./System/Library/Perl/5.8.8/darwin-thread-multi-2level/Encode/Config.p +m ./System/Library/Perl/5.8.8/ExtUtils/MakeMaker/Config.pm ./System/Library/Perl/5.8.8/Net/Config.pm ./System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level/ModPerl/ +Config.pm ./System/Library/Perl/Extras/5.8.8/Module/Build/Config.pm

      Regards,
      Edward
Re: Personal library with CPAN
by osunderdog (Deacon) on Jun 07, 2004 at 14:19 UTC
    I believe if you do:

    perl Makefile.PL PREFIX=/home/username

    then
    make install
    The package will be installed starting at /home/username rather than the standard location.
      PERL5LIB should be also adjusted:
      env PERL5LIB=/home/username/lib/perl perl Makefile.PL PREFIX=/home/use +rname
      (not sure about the exact PERL5LIB value, might be something with perl5 instead).
Re: Personal library with CPAN
by schweini (Friar) on Jun 07, 2004 at 22:42 UTC
    do the proposed solutions work for XS stuff like Tk or DBD::mysql?

    i.e.: can i do this, and then simply copy the CPAN directoy between compatible (x86 with same distro) machines without having to re-install all them modules everywhere?
      Not necessarily. Check that this value is the same:
      "perl -V:archname"
      For example, on my current machine, the value is: i386-freebsd-64int However, another FreeBSD box running the same OS version might not be 64 bit, so the answer would be:
      i386-freebsd

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://361886]
Approved by neniro
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-12-21 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls