Installing modules using CPAN interactive shell in perl

CPANWe have all done this, get a *.tar.gz file from cpan, do a configure, make, test and make install only to realize that the dependencies for the package are missing and then going and fetching them from CPAN and downloading it again and doing the process over and over again. CPAN Shell is one of the many gems that PERL hold and this is how you use it.

Starting the Shell

perl -MCPAN -eshell

Note: You might want to start that command using sudo in case you have permission issues. This depends on your setup.

That shows you the shell.

cpan>

Now give it the command to install (I wanted to install WWW:Mechanize for my little project)

cpan>install WWW::Mechanize

That triggers it go and automatically fetch the package, unpack it and compile it and in the process find all the dependencies. Now this package has a hell lot of dependency and if you plan on installing it manually be prepared for a couple of really long hours. CPAN shell quite intelligent in the way it looks for dependencies and shows you what they are and asking you if it should go and fetch them for you:

Checking if your kit is complete...
Looks good
Warning: prerequisite Sub::Uplevel 0.18 not found.
Warning: prerequisite Test::Builder 0.7 not found. We have 0.32.
Warning: prerequisite Test::Builder::Tester 1.07 not found. We have 1.02.
Warning: prerequisite Test::More 0.7 not found. We have 0.62.
Warning: prerequisite Test::Simple 0.7 not found. We have 0.62.
Writing Makefile for Test::Exception
---- Unsatisfied dependencies detected during [A/AD/ADIE/Test-Exception-0.27.tar.gz] -----
    Test::More
    Test::Builder
    Sub::Uplevel
    Test::Simple
    Test::Builder::Tester
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes]

About rp

Architect for large, highly scalable LAMP applications and Technical Manager with special focus on metrics based continuous improvement of teams and products. Rajat has close to a decade of experience of a very wide range of skills related to infrastructure, middleware, app servers all the way to front-end technologies and software development methodologies including agile, iterative waterfall, waterfall as well as ah-hoc startup using the right approach in the right context to reduce time to market.