Forget about trying to configure cpan
as a non-root user. The easiest solution is just to use cpanm to install your packages and forget about the whole thing.
So do yourself a favour and click that link. Now.
Ok, for some rather bizarre reason you are still reading. I guess you really want to configure cpan
as non-root so, well, let’s do that.
First, to set up the PERL5LIB environment variable, add the following to your ~/.bash_profile
or equivalent:
PERL5LIB=~/perl5lib/lib/:$PERL5LIB
PERL5LIB=~/perl5lib/share/perl/5.8.8:$PERL5LIB
PERL5LIB=~/perl5lib/share/perl/5.8:$PERL5LIB
PERL5LIB=~/perl5lib/lib/perl/5.8.8:$PERL5LIB
PERL5LIB=~/perl5lib/lib/perl/5.8:$PERL5LIB
export PERL5LIB
Reboot or source the file. Then, specially if you are having troubles, you might want to make sure that you are starting with a clean user instalation.
$ cd ~
$ rm -rf .cpan
$ rm -rf perl5lib
Create a folder to hold the modules, and start CPAN
$ mkdir perl5lib
$ cpan
Manual configuration should start, follow the instructions on screen, until at some point the script asks you for any extra arguments for Makefile.PL. You should then supply
PREFIX=~/perl5lib
When the configuration finishes, make sure CPAN tells you it has writen the updated configuration file. If everything seems fine, type quit
.
To install a package now type
$ cpan 'Some::Module'
If things keep failing, you should probably consider doing a manual package install.
Note: if for some reason your script will run in an environment where PERL5LIB
is not (or cannot) be set, then your script should also include
use lib '~/perl5lib/lib/';
use lib '~/perl5lib/share/perl/5.8.8';
use lib '~/perl5lib/share/perl/5.8';
use lib '~/perl5lib/lib/perl/5.8.8';
use lib '~/perl5lib/lib/perl/5.8';
But then, if you need this, you might also need to expand all those ~
’s into their actual absolute paths.