Installing Perl Modules

Jump to navigation Jump to search

Though modern-day Linux and Unix systems may have many perl modules already installed, the time may come when you use a module that was not shipped with your system or installed by your administrator. Don't fret - you can do this all by yourself by using the CPAN module.

Execute the following command to start a CPAN shell:

$ perl -MCPAN -e shell

The first time you run this, an interactive question and answer session will be started as CPAN configures itself. You can take all the defaults until it asks whether you want any parameters for perl Makefile.PL:

Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.
If you don't understand this question, just press ENTER.
Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:
    POLLUTE=1        increasing backwards compatibility
    LIB=~/perl       non-root users (please see manual for more hints)
Your choice:  []

You should answer with the following long line:

PREFIX=~/perl5lib/ LIB=~/perl5lib/lib INSTALLMAN1DIR=~/perl5lib/man1 INSTALLMAN3DIR=~/perl5lib/man3

You can take defaults again until it comes time to choose mirrors of from which you can install from. Choose as many as you like; I chose:

After choosing your mirrors, press enter until you get the cpan> prompt. Then quit (type 'q'). Now tell perl to use your personal module repository by setting the PERL5LIB environment variable, like so:

$ PERL5LIB=~/perl5lib/lib
$ export PERL5LIB

(use setenv if you use csh or tcsh) and fire up CPAN again:

$ perl -MCPAN -e shell

You will be immediately greeted with the cpan> prompt. At the cpan> prompt, enter the following to get CPAN to update itself:

install Bundle::CPAN
reload cpan

and that's it! Now you can install all the modules you want, either from CPAN's interactive shell (perl -MCPAN -e shell) or from the command line (perl -MCPAN -e 'install FOO::BAR').