Installing CPAN Modules
From TechWiki
CPAN ( Comprehensive Perl Archive Network ) can denote either the archive network itself, or the Perl script that acts as an interface to the network and as an automated software installer (somewhat like a package manager). Most software on CPAN is free software.
This articles details the use of CPAN as an automated software installer of Perl Modules.
Contents |
Why CPAN
Most ( Sane ) Perl modules do not rewrite all the code required for that specific modules. Instead each modules is built up on privious modules. The base modules in Perl are of course an exception to this. What this means is that say for example you want to install Email::Send::SMTP. This modules requires the following other modules
- Test::More
- Module::Pluggable
- Scalar::Util
- File::Spec
- Symbol
- Return::Value
- Email::Simple
- Email::Address
In the above list of what is know as dependencies, the first five are core Modules. That means that you will not have to install them. However the others are not. It turns out that to install Email::Send::SMTP you need to install the others.
It so happens that each of these other modules in this case do not have further non-core dependencies. However that is not always the case and very often you end up having to deal with cascading dependencies. This is often further complicated by the fact that the various modules that you would want to install require different versions of the same modules.
Downloading the source of each of these packages and installing them by hand can be quite a task.
Enter CPAN
Prerequisites
This article assumes that the user is familiar with:
- Perl
- Programming in Perl
Although this section describes the use of CPAN on Linux systems it is possible to use similar methods on non-linux systems as well.
NOTE: This Article deals with the installation of modules as a root user. To install CPAN Modules as a non-root user see this.
Installing the base
Most Linux systems come with a pre-installed version of Perl. This also includes a simple interface to install modules from CPAN. Most often all you need to do is:
perl -MCPAN -e "install Module::Name::Here"
NOTE: You will be asked to configure CPAN. The following are some important configuration settings that you need to be aware of:
- Parameters for the './Build install' command? Typical frequently used setting: SET TO --uninst 1
However if you intend to install Perl Modules on a regular basis its a good idea to install Bundle CPAN
Installing Bundle::CPAN
Most of the time installing Bundle::CPAN is as simple as executing
sudo perl -MCPAN -e "install Bundle::CPAN"
Installing CPAN On Ubuntu Hardy
You need to first use apt-get to install some base packages:
sudo apt-get install build-essential
Now invoke the CPAN shell by use of
sudo perl -MCAPN -e "shell"
Once this is done you will be asked to configure CPAN. The following are some important configuration settings that you need to be aware of:
- Parameters for the './Build install' command? Typical frequently used setting: SET TO --uninst 1
Now you need to install some basic installation files by use of
cpan>make install
And you are done - however you might still want to install Bundle::CPAN.
Common Errors
Perl may be unconfigured (Can't locate IO/File.pm in @INC ... or cant locate some other .pm in @INC
Most of the time this is due to errors in the CPAN mirror selected. You need to Change your mirrors ( you should have select this during CPAN setup. This is not really easy cause your entire CPAN module will fail.
So here is what needs to be done:
re-install the Perl base
sudo apt-get install --reinstall perl-base
You might get an error when doing this - simply re-run the command.
now use
$ perl -MCPAN -e "shell"
cpan> o conf init
To select a new mirror.

