I recently had the problem to install some PERL modules from CPAN with a non-root user. As a non-root user you won’t be able to install modules in non-system locations (system location would be: /usr/bin, /usr/lib). Luckily you can also install modules into your home directory. First you need to determine wether or not you need to configure CPAN.

perl -MCPAN -e shell

This might result in the following error message:

  Your configuration suggests "/root/.cpan" as your
  CPAN.pm working directory. I could not create this directory due
  to this error: mkdir /root/.cpan: Permission denied at /usr/lib/perl5/5.8.8/CPAN.pm line 553

If you don’t get this error message you are already done and you can stop reading. Otherwise you need to re-configure CPAN for your personal use.

1
2
3
4
5
6
mkdir -p ~/lib/perl5
echo 'export PERL5LIB=${PERL5LIB}:~/lib/perl5:~/lib/perl5/lib:~/lib/perl5/lib/i586-linux-thread-multi/' >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/.cpan/CPAN
echo "\$CPAN::Config = {}"> ~/.cpan/CPAN/MyConfig.pm
perl -MCPAN -e shell

NOTE: the shell variable PERL5LIB also contains an architecture dependent lib-path. So it might be that you need to change that part of the lib-path, e.g. from ~/lib/perl5/lib/i586-linux-thread-multi/ to ~/lib/perl5/lib/i386-linux-thread-multi/ or whatever your system matches.

Accept all the defaults (as long as you don’t want to make any special settings) until you reach the following question:

  Every Makefile.PL is run by perl in a separate process. Likewise we
  run 'make' and 'make install' in processes. If you have any
  parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
  to the calls, please specify them here.
 
  If you don't understand this question, just press ENTER.
 
  Parameters for the 'perl Makefile.PL' command?
  Typical frequently used settings:
 
  PREFIX=~/perl non-root users (please see manual for more hints)

Give the following answer:

1
2
PREFIX=~/lib/perl5 LIB=~/lib/perl5/lib INSTALLMAN1DIR=~/lib/perl5/man1 INSTALLMAN3DIR=~/lib/perl5/man3
...

That’s it, now you should be able to install PERL modules from CPAN via the CPAN shell.