Perl: How do I install Perl modules? eg. Installing LWP module for Perl.

The easiest way to install Perl modules is by installing them through “shell”. Let us say that you are trying to install very common module called: LWP

You can test to see if you have LWP installed by typing:
perl -MLWP -le "print(LWP->VERSION)"
If you get something like: Can’t locate LWP.pm in @INC means that you don’t have it installed. To install LWP, type:
perl -MCPAN -eshell
NOTE: most times it is okey for you to accept default answers to questions cpan asks.
You can read through cpan help by typing “h” without the quotes at cpan> prompt.
To continue installing LWP, type:
install Bundle::LWP
After few questions, and some text scrolling, you will have LWP installed. If for some reason you don’t want to do it this way, you can always obtain source for the module you are trying to install and build it from source files. You can obtain these files from CPAN site

11 thoughts on “Perl: How do I install Perl modules? eg. Installing LWP module for Perl.

  1. adil ismael

    getting error by intalling perl module
    new to linux cpan

    # perl -MCPAN -eshell
    Terminal does not support AddHistory.

    cpan shell — CPAN exploration and modules installation (v1.7602)
    ReadLine support available (try ‘install Bundle::CPAN’)

    cpan> install Bundle::LWP
    CPAN: Storable loaded ok
    Going to read /usr/src/perll/asterisk-perl-0.05/yes/sources/authors/01mailrc.txt.gz
    yes: invalid option — –
    Try `yes –help’ for more information.
    Going to read /usr/src/perll/asterisk-perl-0.05/yes/sources/modules/02packages.details.txt.gz
    yes: invalid option — –
    Try `yes –help’ for more information.
    Warning: Your /usr/src/perll/asterisk-perl-0.05/yes/sources/modules/02packages.details.txt.gz does not contain a Line-Count header.
    Please check the validity of the index file by comparing it to more
    than one CPAN mirror. I’ll continue but problems seem likely to
    happen.
    Warning: Your /usr/src/perll/asterisk-perl-0.05/yes/sources/modules/02packages.details.txt.gz does not contain a Last-Updated header.
    Please check the validity of the index file by comparing it to more
    than one CPAN mirror. I’ll continue but problems seem likely to
    happen.
    Going to read /usr/src/perll/asterisk-perl-0.05/yes/sources/modules/03modlist.data.gz
    yes: invalid option — –
    Try `yes –help’ for more information.
    Can’t locate object method “data” via package “CPAN::Modulelist” (perhaps you forgot to load “CPAN::Modulelist”?) at (eval 20) line 1.
    at /usr/lib/perl5/5.8.8/CPAN.pm line 3405
    CPAN::Index::rd_modlist(‘CPAN::Index’, ‘/usr/src/perll/asterisk-perl-0.05/yes/sources/modules/03modli…’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 3128
    CPAN::Index::reload(‘CPAN::Index’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 785
    CPAN::instance(‘CPAN=HASH(0x89a12bc)’, ‘CPAN::Bundle’, ‘Bundle::DBI’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 1427
    CPAN::Shell::local_bundles(‘CPAN::Shell’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 1835
    CPAN::Shell::expandany(‘CPAN::Shell’, ‘Bundle::LWP’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 2077
    CPAN::Shell::rematein(‘CPAN::Shell’, ‘install’, ‘Bundle::LWP’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 2164
    CPAN::Shell::install(‘CPAN::Shell’, ‘Bundle::LWP’) called at /usr/lib/perl5/5.8.8/CPAN.pm line 201
    eval {…} called at /usr/lib/perl5/5.8.8/CPAN.pm line 201
    CPAN::shell() called at -e line 1

    cpan>

    don’t know what to do
    will anybody guide

  2. Pingback: MySQL: How do you install innotop to monitor innodb in real time? | Technology: Learn and Share

  3. Abhishek Singh

    I’ve the same problem:

    Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
    Going to read /root/.cpan/sources/modules/02packages.details.txt.gz
    Warning: Your /root/.cpan/sources/modules/02packages.details.txt.gz does not contain a Line-Count header.
    Please check the validity of the index file by comparing it to more
    than one CPAN mirror. I’ll continue but problems seem likely to
    happen.
    Warning: Your /root/.cpan/sources/modules/02packages.details.txt.gz does not contain a Last-Updated header.
    Please check the validity of the index file by comparing it to more
    than one CPAN mirror. I’ll continue but problems seem likely to
    happen.
    Going to read /root/.cpan/sources/modules/03modlist.data.gz
    Can’t locate object method “data” via package “CPAN::Modulelist” (perhaps you forgot to load “CPAN::Modulelist”?) at (eval 13) line 1.
    at /usr/lib/perl5/5.8.5/CPAN.pm line 3406
    CPAN::Index::rd_modlist(‘CPAN::Index’, ‘/root/.cpan/sources/modules/03modlist.data.gz’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 3129
    CPAN::Index::reload(‘CPAN::Index’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 786
    CPAN::instance(‘CPAN=HASH(0xa3e8604)’, ‘CPAN::Bundle’, ‘Bundle::Apache2’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 1428
    CPAN::Shell::local_bundles(‘CPAN::Shell’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 1836
    CPAN::Shell::expandany(‘CPAN::Shell’, ‘Bundle::CPAN’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 2078
    CPAN::Shell::rematein(‘CPAN::Shell’, ‘install’, ‘Bundle::CPAN’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 2165
    CPAN::Shell::install(‘CPAN::Shell’, ‘Bundle::CPAN’) called at /usr/lib/perl5/5.8.5/CPAN.pm line 201
    eval {…} called at /usr/lib/perl5/5.8.5/CPAN.pm line 201
    CPAN::shell() called at /usr/bin/cpan line 193

    I’m using RHEL 4. Performing cpan -i Bundle::CPAN does not solve the problem, rather reiterates it.

    What could be the solution. Thanks in advance.

  4. Ben

    tried installing Bundle::LWP

    got this:

    Going to read /home/admin/.cpan/sources/authors/01mailrc.txt.gz
    Could not pipe[/bin/gzip –decompress –stdout /home/admin/.cpan/sources/authors/01mailrc.txt.gz |]: Cannot allocate memory at (eval 20) line 5727, line 9.

    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *