3.28.2011

How to install perl modules with CPAN (perl-cpan)

The following should work with all newer versions Fedora, Centos, or Red Hat.

In this article we will cover the basics of installing perl modules with perl-CPAN.

Prerequisite:
You will need to have GNU C Compiler installed on your system.  It can be installed by running the following command as root:
yum -y install gcc

The following steps should be run as root user.

First we need to install perl-CPAN with the following command:

yum -y install perl-CPAN

Now that we have perl-CPAN installed, we now have to configure it, or better yet, let it configure itself.

Run the following command:

cpan

You will be presented with the following:



CPAN is the world-wide archive of perl resources. It consists of about
300 sites that all replicate the same contents around the globe. Many
countries have at least one CPAN site already. The resources found on
CPAN are easily accessible with the CPAN.pm module. If you want to use
CPAN.pm, lots of things have to be configured. Fortunately, most of
them can be determined automatically. If you prefer the automatic
configuration, answer 'yes' below.


If you prefer to enter a dialog instead, you can answer 'no' to this
question and I'll let you configure in small steps one thing after the
other. (Note: you can revisit this dialog anytime later by typing 'o
conf init' at the cpan prompt.)
Would you like me to configure as much as possible automatically? [yes]

Hitting enter will tell cpan to try to configure itself. (So hit enter)

The screen will scroll with a lot of information, then you will be presented with the following prompt (if all went well)

cpan[1]>


This is the cpan shell prompt.  From here it is simple to install all your perl modules.  For this example we will install Term::ReadKey which is a small module that allows you to hide passwords typed on the command line in perl scripts.





At the cpan prompt (cpan[1]> )type the following:

cpan[1]> install Term::ReadKey


CPAN will not fetch the necessary files and install them for you.

NOTE: Some people have reported issues when using a proxy server.  The simplest way around this is to export the http_proxy variable as root.

export http_proxy=http://fqdn_of_proxy.com:port

example:
export http_proxy=http://example.com:8080

If you use cpan a lot you can add the http_proxy variable to root .bashrc file so it will always be available without you typing the export command each time.

0 comments:

Post a Comment