Blog

Installing a CPAN Perl module from a non-root account

Source: http://www.soe.ucsc.edu/~you/notes/perl-module-install.html

Problem: you do not have root permission but want to install a Perl module in a local directory and the module can be located from your scripts.

CPAN Perl modules

Refer to Installing CPAN Modules and this section in the CPAN FAQ.

Download the Perl module

Find the Perl module you want. Google or the CPAN Search Site are usually good ways to find the module. Download a copy of the entire package (usually a .tar.gz, not the individual .pm "Perl module" file) into a download directory. I usually keep a directory named ~/downloads.

Install the Perl module into your ~/lib directory

Unpack the CPAN Perl module:

cd ~/src
tar -zxvf ~/downloads/Statistics-Descriptive-2.6.tar.gz

(The conventional installation method is:

cd ~/src/Statistics-Descriptive-2.6
perl Makefile.PL
make
make test
make install

)

But specify the installation into ~/lib/perl5 instead:

cd ~/src/Statistics-Descriptive-2.6
perl Makefile.PL PREFIX=~/lib/perl5
make
make test
make install

Installing /home/you/lib/perl5/site_perl/5.8.2/Statistics/Descriptive.pm
Writing /home/you/lib/perl5/site_perl/5.8.2/cygwin-thread-multi-64int/auto/Statistics/Descriptive/.packlist
Appending installation info to /home/you/lib/perl5/5.8.2/cygwin-thread-multi-64int/perllocal.pod

Change your Perl scripts so that they can find the Perl module that you have installed locally

See this section in the CPAN FAQ.

I prefer the first method that is mentioned, which is to set the environment variable. This is easy to do in a login script.

setenv PERL5LIB /path/to/module sets the environment variable PERL5LIB.

With Bash:

 export PERL5LIB=~/lib/perl5/site_perl

Remove the Perl module

Just remove the appropriate files from ~/lib/perl5. Or use the  ExtUtils package to help you remove the files.