Sunday, 5 February 2012

How to install Perl Module using CPAN

Install Perl Module using CPAN


At times, we need to install Perl modules that are not found in the official repository of a distribution. In that case, we have to revert to using cpan. CPAN stands for Comprehensive Perl Archive Network. It is an archive of over 16,000 modules of software written in Perl, as well as documentation for it. This tutorial will show you how to install a module using CPAN.

First we need to launch cpan. Type cpan in a terminal. If it is not already configured, then it will start to ask a series of questions. Just press Enter all the way until it asks for your location. Specify the location by entering the number for that location in the list shown. Then it will ask about your country, go ahead and type the number appropriate for your country. At the end you will see the cpan prompt like so


cpan>

To install a module, for example, Cache::Static, type the following at cpan prompt

cpan>install Cache::Static

It will ask you some questions, just press Enter to accept the defaults which almost always work. The module with all its dependencies will be downloaded, compiled and installed.

When you get back the cpan prompt, the module is installed.
Type quit to get out of cpan

cpan>quit

To confirm that the module is installed successfully, run this command

perl -e "use Cache::Static"

If you get no output, it means the module is installed successfully.

If you see the error “/bin/sh: cc: command not found”, then gcc is not installed. Install it like this on Debian, Ubuntu

aptitude install gcc

On Red Hat, Centos, Fedore, the following will work

yum install gcc

No comments:

Post a Comment