Using CPAN

From Dev411: The Code Wiki

Table of contents

Configuration

To us the CPAN shell the first thing you need to do is configure it. Configuration is pretty straight-forward if you have superuser privileges but can be tricky if you do not. Local installation is described below

Local installation

If you are on a shared system and do not have permissions to install into the system directories, installation is a bit more involved. First you'll need to configure CPAN to use your local directory and then use CPAN. This information is from the 2005 Catalyst Advent Calendar (http://www.catalystframework.org/calendar/2005/10). These instructions assume you will install the files under the ~/local directory which you should create.

Configuring CPAN

If you haven't configured CPAN already, do so by typing:

$ perl -MCPAN -e shell

Answer the configuration questions and then quit without installing anything.

Configuring local directories

Edit the ~/.bashrc file and add the following:

export PATH=$HOME/local/bin:$HOME/local/script:$PATH
perlversion=`perl -v | grep 'built for' | awk '{print $4}' | sed -e 's/v//;'`
export PERL5LIB=$HOME/local/share/perl/$perlversion:$HOME/local/lib/perl/$perlversion:$HOME/local/lib:$PERL5LIB

Reload .bashrc with the following to update your environment:

$ source ~/.bashrc

Edit ~/.cpan/CPAN/MyConfig.pm

Look for the make_install_arg and makepl_arg configuration variables and set them to the following:

'make_install_arg' => qq[SITEPREFIX=$ENV{HOME}/local],
'makepl_arg' => qq[INSTALLDIRS=site install_base=$ENV{HOME}/local],

On Dreamhost, with their 5.8.4 /usr/local/bin/perl, $ENV{HOME} and install_base wouldn't work for me so I ended up hardcoding the local directory like the following where <username> is your *nix username:

'make_install_arg' => qq[SITEPREFIX=/home/<username>/local],
'makepl_arg' => qq[INSTALLDIRS=site PREFIX/home/<username>/local],

Installing via CPAN shell

Now just do a normal CPAN installation to make sure it works. I installed Plagger on Dreamhost as a test:

$ perl -MCPAN -e shell
cpan> install Plagger

Configuring FTP

If FTP is not working, you may need to set your FTP mode to permissive. To do this edit Net::Config and set ftp_ext_passive to any positive non-0 value:

 ftp_ext_passive => 1,

Resetting CPAN's State

To reset CPAN's state remove the .cpan and site directories with:

 rm -rf ~/.cpan
 rm -rf ~/site

Sometimes it can be fine to remove ~/site on a regular basis.

See Also

Installing Perl Modules