CPAN can be configured differently for each user, and can install modules to custom areas on a system. The sample configuration below installs modules under ~/lib/perl5, man pages under ~/share/man and (hopefully) everything else under the home directory. This approach also works for individual software trees required for special applications that run as non-privileged accounts: simply adjust the installation paths to suit the software depot in question.
Download the sample MyConfig.pm, and move it to ~/.cpan/CPAN/MyConfig.pm.
mkdir -p ~/.cpan/CPAN
$ mv MyConfig.pm ~/.cpan/CPAN
Check the paths to various commands (e.g. wget), proxy settings for your environment, the urllist, and the shell.
Be sure to remove the UNINST=1 option on make_install_arg for any non-system-wide configuration as otherwise CPAN will attempt to remove “shadowing” versions of the module installed for the site perl, leading to error messages involving forceunlink.
Test MyConfig.pm for problems.
perl -c MyConfig.pm
MyConfig.pm syntax OK
Test the new configuration.
To ensure Makefile are being generated with the proper paths, make a module from the CPAN shell, then review at the paths set in the resulting Makefile.
cpan> look Text::Autoformat
$ less Makefile
$ grep /home/username Makefile
SITELIBEXP = /home/username/lib/perl5
PREFIX = /home/username/
INSTALLPRIVLIB = /home/username/lib/perl5
INSTALLSITELIB = /home/username/lib/perl5
INSTALLVENDORLIB = /home/username/lib/perl5
INSTALLARCHLIB = /home/username/lib/perl5/darwin-thread-multi-2level
INSTALLSITEARCH = /home/username/lib/perl5/darwin-thread-multi-2level
INSTALLVENDORARCH = /home/username/lib/perl5/darwin-thread-multi-2level
INSTALLMAN1DIR = /home/username/share/man/man1
INSTALLSITEMAN1DIR = /home/username/share/man/man1
INSTALLMAN3DIR = /home/username/share/man/man3
INSTALLSITEMAN3DIR = /home/username/share/man/man3
If the Makefile has the wrong path set for any variables, update the makepl_arg arguments in MyConfig.pm to set these variables to install to the proper custom location.
Perl must be made aware of the custom /home/username/lib/perl5 library directory. Perl uses the @INC variable to hold library directories, though this varible must not be edited directly. For more information on @INC, consult perlvar (overview of variable), perlrun (command line arguments and environment variables), or lib (use lib pragma). Under a Bourne shell (such as zsh), use the following to set PERL5LIB and MANPATH environment variables.
if [ -d $HOME/lib/perl5 ]; then
export MANPATH PERL5LIB
Code running under Taint mode may require the use lib statement: see perlsec for details. Other applications may include different methods of setting custom environment setting, such as SetEnv under Apache:
SetEnv PERL5LIB /home/username/lib/perl5:/sw/lib/perl5