Perl: Installing Modules

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 determine which modules you need, you'll have to download and install them. The can be found from the CPAN Site

Please take a 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:
  • 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 specifiy 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

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

  • Test. This is usually done using make test.

  • 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 -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) called HTML::Parser, LWP::UserAgent and Net::IP type in the following.


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

Published: Sunday, 28 March 2004