Set my CPAN install directory
May 25, 2004 9:04 PM   Subscribe

I want the CPAN shell to install modules it's done building to a directory other than /usr/lib/perl5blahetc (largely because I am not root on this particular server and won't be). This being perl I'd be _highly_ surprised if there's no way to set the installation directory, but a quick perusal of the CPAN shell settings gives no such option. Nor does a similarly quick perusal of ~/.cpan/.

Sometimes I find a similar problem when trying to build perl moduels by hand... it just seems to *assume* that I want to install to /usr/lib/perl5yaddayadda when I type make install. How do I control this stuff?
posted by namespan to Technology (5 answers total)
 
The cpan command "o" lets you set options, and the "makepl_arg" option sets the list of arguments passwd to the "perl Makefile.pl" command when installing modules. And the standard is for Perl module makefiles to take the PREFIX argument to set the install path. So:

cpan> o conf makepl_arg 'PREFIX=/home/you/lib/perl5'
cpan> install whatever

should do what you want.
posted by nicwolff at 9:53 PM on May 25, 2004


Oh, and when building by hand you can just do "perl Makefile.PL PREFIX=/home/you/lib/perl5" before you "make" and "make install".
posted by nicwolff at 9:56 PM on May 25, 2004


Oh! And apparently you can set up a personal MyConfig.pm as described in this article, which is full of good tips about running Perl and Apache without root privileges.
posted by nicwolff at 10:15 PM on May 25, 2004


Response by poster: Thanks nicwolff -- o conf works pretty well. The exception seems to be if you end up trying to build something that has uninstalled dependencies... in which case the CPAN shell carps because it doesn't know /home/me/local/perlhooplah should be in @INC.

To fix this, I tried:

perl -MCPAN -e shell -I/home/me/local/perlhooplah

but this didn't seem to work.

Other techniques? (Sorry if it's in the article -- I did read it, and it's way cool, but I couldn't extract this particular bit of wisdom from it...)
posted by namespan at 11:29 PM on May 25, 2004


Here's the relevant part of that article:

-----

When you start the CPAN interactive shell, it searches first for
the user's private configuration file and then for the system-wide
one. When I'm logged as user stas, the two files on my setup are:

/home/stas/.cpan/CPAN/MyConfig.pm
/usr/lib/perl5/5.00503/CPAN/Config.pm

If there is no CPAN shell configured on your system, then when you start
the shell for the first time it will ask you a dozen configuration
questions and then create the Config.pm file for you.
If you already have it system-wide configured, then you should have a
/usr/lib/perl5/5.00503/CPAN/Config.pm. If you have a different
Perl version, then alter the path to use your Perl's version number when
looking up the file. Create the directory (mkdir -p creates the
whole path at once) where the local configuration file will go:

% mkdir -p /home/stas/.cpan/CPAN

Now copy the system wide configuration file to your local one.

% cp /usr/lib/perl5/5.00503/CPAN/Config.pm \
/home/stas/.cpan/CPAN/MyConfig.pm

The only thing left is to change the base directory of .cpan in
your local file to the one under your home directory. On my machine, I
replace /usr/src/.cpan (that's where my system's .cpan directory
resides) with /home/stas. I use Perl, of course!

% perl -pi -e 's|/usr/src|/home/stas|' \
/home/stas/.cpan/CPAN/MyConfig.pm

Now you have the local configuration file ready, you have to tell it
what special parameters you need to pass when executing the perl
Makefile.PL
stage.
Open the file in your favorite editor and replace line:

'makepl_arg' => q[],

with:

'makepl_arg' => q[PREFIX=/home/stas],

Now you've finished the configuration. Assuming that you are logged
in as the same user you have prepared the local installation for
(stas in our example), start it like this:

% perl -MCPAN -e shell

From now on, any module you try to install will be installed locally.
If you need to install some system modules, then just become the superuser
and install them in the same way. When you are logged in as the
superuser, the system-wide configuration file will be used instead of
your local one.
posted by nicwolff at 6:32 AM on May 26, 2004 [1 favorite]


« Older Learning a New City   |   Protozoa Newer »
This thread is closed to new comments.