Rate this page

Flattr this

Install a Perl module

Tested on

CentOS (5.5)
Debian (Lenny, Squeeze)
Fedora (14)
OpenSUSE (11.3)
Ubuntu (Hardy, Intrepid, Jaunty, Karmic, Lucid, Maverick)


To install a Perl module


Suppose that you wish to install the module Data::Compare.

Method (package manager)

If Perl module you need has been packaged for the operating system you are using then installing it is simply a matter of invoking the package manager. For example, the Data::Compare module can be installed on Debian-based systems using the apt-get command:

apt-get install libdata-compare-perl

and on Red Hat-based systems using yum:

yum install perl-Data-Compare

One advantage of this method is that it can automatically handle any required dependencies of the module (including dependencies that are not Perl modules). Potential drawbacks are that the module you need may not have been packaged, or may not be a sufficiently recent version.

The package name used by the package manager is not normally the same as the Perl module name, however there is usually a predictible relationship between them. The naming convention for Debian-based systems is to:

  1. convert the Perl module name to lower case, then
  2. replace all double-colons with hyphens, then
  3. prepend ‘lib’ and append ‘-perl’.

Red Hat-based systems use a different convention:

  1. replace all double-colons with hyphens, then
  2. prepend ‘perl-’.

For example, the table below shows how the DBI, Data::Compare and Net::IMAP::Simple modules are named as packages:

Perl Debian Red Hat
DBI libdbi-perl perl-DBI
Data::Compare libdata-compare-perl perl-Data-Compare
Net::IMAP::Simple libnet-imap-simple-perl perl-Net-IMAP-Simple

Method (build and install automatically)

Perl modules that are available from CPAN can be downloaded, unpacked and built automatically using the cpan command, which is an interface to the CPAN.pm Perl module. For example, the command to install the Data::Compare module would be:

cpan -i Data::Compare

Because this is a Perl-specific facility it uses standard Perl module names. It can automatically handle dependencies that are Perl modules, but not (for example) any C libraries that might be needed.

Method (build and install manually)

Perl modules are normally distributed as gzipped tarballs which can be decompressed using the tar command:

tar zxfo Data-Compare-1.2101.tar.gz

This should create a directory called Data-Compare-1.2101 containing the module source code. The normal procedure for building it would be:

cd Data-Compare-1.2101
perl Makefile.PL

however if there are any module-specific instructions (usually in a file called README or INSTALL) then you should read these first.

Most modules include test scripts, which you should run to ensure that the module has been built correctly:

make test

Finally, install the module:

make install


You can check that a Perl module has been installed by attempting to load it:

perl -e "use Data::Compare;"

If no error message is displayed then the module was loaded successfully. If it was not successfully loaded then you should see an error similar to:

Can't locate Data/Compare.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

Further reading

Tags: perl