Perl: Installing Modules

Published: Sunday, 28 March 2004

Install Modules

This articles assumes you are compiling the modules and installing them yourself. If possible, it is often easier to use a package manager such as rpm on linux, or ppm for ActivePerl. After determining which modules you need, you’ll have to download and install them. They can be found from CPAN.

Look at the documentation that comes with module you downloaded. You may find special installation instructions, and readme files.

Manual Installation

Typically there are 4 steps:

  1. Create the Makefile. Usually this is accomplished by perl Makefile.PL. Note that there are other options available here such as PREFIX that will allow you to specify where the module should be installed. I use this to test modules in my own private directory. e.g. the full command line may be: perl Makefile.PL PREFIX=/home/jurn/perl

  2. Compile. This is done using the standard make utility.

  3. Test. This is usually done using make test.

  4. Installation. This is done by issuing a make install. You will need to be root for this, unless you specified a non-standard installation directory when creating the Makefile. If you forgot, you can also modify the Makefile at this stage before issuing the make install command.

If you installed the modules to a non-standard directory you can use the environment variable PERL5LIB when running your scripts. PERL5LIB depends on the PREFIX directory you specified when creating the Makefile.

In the example above, the module ended up in the following directory /home/jurn/perl/lib/perl5/site_perl/5.8.3/i686-linux/ so that is what PERL5LIB should be set to.

Automatic Installation

At the prompt,

$ perl -MCPAN -eshell

perl will ask you for some configuration, such as where the closest CPAN repository is, and how to access it. If you’ve configured it properly, you will get to the cpan prompt. From here you can enter the install command and perl will download, compile and install the modules into your local system.

e.g. To install the 3 modules (and all required dependencies) HTML::Parser, LWP::UserAgent and Net::IP type in the following.

cpan> install HTML::Parser LWP::UserAgent Net::IP