When you start the CPAN interactive shell, it searches first for the
user's private configuration file and then for the
system-wide one. For example, for a user stas
and Perl Version 5.6.1, it will search for the following
configuration files:
/home/stas/.cpan/CPAN/MyConfig.pm
/usr/lib/perl5/5.6.1/CPAN/Config.pm
If there is no CPAN shell configured on your system, 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 the CPAN shell is already configured system-wide, you should
already have a
/usr/lib/perl5/5.6.1/CPAN/Config.pm file. (As
always, if you have a different Perl version, the path will include a
different version number.) Create the directory for the local
configuration file as well:
panic% mkdir -p /home/stas/.cpan/CPAN
(On many systems, mkdir -p creates the whole
path at once.)
Now copy the system-wide configuration file to your local one:
panic% cp /usr/lib/perl5/5.6.1/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 our machine, we replace
/root/.cpan (which is where our
system's .cpan directory
resides) with /home/stas. Of course, we use Perl
to edit the file:
panic% perl -pi -e 's|/root|/home/stas|' \
/home/stas/.cpan/CPAN/MyConfig.pm
Now that you have the local configuration file ready, you have to
tell it what special parameters you need to pass when executing
perl Makefile.PL. Open the file in your favorite
editor and replace the following line:
'makepl_arg' => q[ ],
with:
'makepl_arg' => q[PREFIX=/home/stas],
Now you've finished the configuration. Assuming that
you are logged in with the same username used for the local
installation (stas in our example), start it
like this:
panic% 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, 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.
If you have used more than just the PREFIX
variable, modify MyConfig.pm to use the other
variables. For example, if you have used these variables during the
creation of the Makefile:
panic% perl Makefile.PL PREFIX=/home/stas \
INSTALLPRIVLIB=/home/stas/lib/perl5 \
INSTALLSCRIPT=/home/stas/bin \
INSTALLSITELIB=/home/stas/lib/perl5/site_perl \
INSTALLBIN=/home/stas/bin \
INSTALLMAN1DIR=/home/stas/lib/perl5/man \
INSTALLMAN3DIR=/home/stas/lib/perl5/man3
replace PREFIX=/home/stas in the line:
'makepl_arg' => q[PREFIX=/home/stas],
with all the variables from above, so that the line becomes:
'makepl_arg' => q[PREFIX=/home/stas \
INSTALLPRIVLIB=/home/stas/lib/perl5 \
INSTALLSCRIPT=/home/stas/bin \
INSTALLSITELIB=/home/stas/lib/perl5/site_perl \
INSTALLBIN=/home/stas/bin \
INSTALLMAN1DIR=/home/stas/lib/perl5/man \
INSTALLMAN3DIR=/home/stas/lib/perl5/man3
],