How to install a Perl Module from CPAN

Developers and admins who are new to Perl might wonder how they can install one of the 18.000 available Perl Modules from http://search.cpan.org.

One of the many ways to do this is to call the CPAN shell from the Unix command line, like so:

cpan Modern::Perl

You could also go and give the cpan command a list of modules that you like to install:

cpan Modern::Perl DBI YAML JSON::XS

However, if you just type in "cpan" you start the interactive CPAN shell, where you can install a module by typing:

install Modern::Perl

If you just type in “i Modern::Perl” you get just some information about the module.

The CPAN shell downloads the archive into your ~/.cpan/build directory and extracts the content there. If the module can not be installed because tests are failing, you could go into that directory and do a

perl Makefile.PL
make
make test
make install

by hand and eventually fix the problem that caused the tests to fail - or just force to install the module and ignore the tests if you know what you’re doing.

Leave a comment

About Marc

user-pic I am a Perl developer and CPAN author. I develop software with Perl since 1996 and Perl is still one of my favorite programing languages.