Wednesday, January 29, 2014

Install CPAN modules in Perl

To install modules from CPAN, run the following command as administrator

perl -MCPAN -e shell
or
cpan
Under the CPAN shell, type in

install Module_Name

For example, to support the command line history in CPAN shell, we need to install the modules

install Term::ReadLine
install Term::ReadLine::Perl

To customize installation path, eg, when installing without root privilege, run the following commands in cpan (Ref 1):
o conf mbuildpl_arg '--install_base /home/user/.local/perl5'
o conf makepl_arg INSTALL_BASE=/home/user/.local/perl5
o conf commit

Once installation path is customized, set environment variable PERL5LIB to tell perl where to look for modules from, eg, add one line in ~/.bash_profile:
export PERL5LIB=/home/user/.local/perl5/lib/perl5:$PERL5LIB
Setup MANPATH
MANPATH=$MANPATH:/home/user/.local/man

Update
We can also use cpanm to facilitate installation from CPAN or from local (*.tar.gz) file. Firstly type in this command in terminal

cpan App::cpanminus

Now, install module

cpanm CPAN_Module_Name
cpanm -l /path/to/install perl_package_file #-l option specifies installation location

Reference
1. Setting up customized installation path for cpan:
http://stackoverflow.com/questions/540640/how-can-i-install-a-cpan-module-into-a-local-directory