CPAN(Comprehensive Perl Archive Network) is an online portal(http://www.cpan.org) and a repository of PERL modules written by community. The beauty of this online resource is we can download and install these modules in to your machine with CPAN command. This tutorial show you how to install and configure CPAN in Linux operating systems like Redhat, Fedora, CentOS, Ubuntu etc.

Install CPAN package in Ubuntu/Debian

apt-get install build-essential

Install CPAN package In Redhat/Centos/Fedora

Installing CPAN package in Redhat/CentOS/Fedora:

	yum install perl-CPAN

Output:

	[root@www Desktop]# yum install perl-CPAN
	Loaded plugins: fastestmirror, refresh-packagekit, security
	Determining fastest mirrors
	* base: centos.mirror.net.in
	* extras: centos.mirror.net.in
	* updates: centos.mirror.net.in
	base | 3.7 kB 00:00
	extras | 3.5 kB 00:00
	updates | 3.4 kB 00:00
	updates/primary_db | 2.9 MB 00:01
	Setting up Install Process
	Resolving Dependencies
	--> Running transaction check
	---> Package perl-CPAN.i686 0:1.9402-131.el6_4 will be installed
	--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: perl-CPAN-1.9402-131.el6_4.i686
	--> Processing Dependency: perl(Digest::SHA) for package: perl-CPAN-1.9402-131.el6_4.i686
	--> Running transaction check
	---> Package perl.i686 4:5.10.1-119.el6_1.1 will be updated
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 4:perl-devel-5.10.1-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 1:perl-Pod-Escapes-1.04-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: perl-Test-Simple-0.92-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 1:perl-Module-Pluggable-3.90-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: perl-ExtUtils-MakeMaker-6.55-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: perl-Test-Harness-3.17-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 3:perl-version-0.77-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 1:perl-ExtUtils-ParseXS-2.2003.0-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 4:perl-libs-5.10.1-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: 1:perl-Pod-Simple-3.13-119.el6_1.1.i686
	--> Processing Dependency: perl = 4:5.10.1-119.el6_1.1 for package: perl-CGI-3.51-119.el6_1.1.i686
	---> Package perl.i686 4:5.10.1-131.el6_4 will be an update
	---> Package perl-Digest-SHA.i686 1:5.47-131.el6_4 will be installed
	--> Running transaction check
	---> Package perl-CGI.i686 0:3.51-119.el6_1.1 will be updated
	---> Package perl-CGI.i686 0:3.51-131.el6_4 will be an update
	---> Package perl-ExtUtils-MakeMaker.i686 0:6.55-119.el6_1.1 will be updated
	---> Package perl-ExtUtils-MakeMaker.i686 0:6.55-131.el6_4 will be an update
	---> Package perl-ExtUtils-ParseXS.i686 1:2.2003.0-119.el6_1.1 will be updated
	---> Package perl-ExtUtils-ParseXS.i686 1:2.2003.0-131.el6_4 will be an update
	---> Package perl-Module-Pluggable.i686 1:3.90-119.el6_1.1 will be updated
	---> Package perl-Module-Pluggable.i686 1:3.90-131.el6_4 will be an update
	---> Package perl-Pod-Escapes.i686 1:1.04-119.el6_1.1 will be updated
	---> Package perl-Pod-Escapes.i686 1:1.04-131.el6_4 will be an update
	---> Package perl-Pod-Simple.i686 1:3.13-119.el6_1.1 will be updated
	---> Package perl-Pod-Simple.i686 1:3.13-131.el6_4 will be an update
	---> Package perl-Test-Harness.i686 0:3.17-119.el6_1.1 will be updated
	---> Package perl-Test-Harness.i686 0:3.17-131.el6_4 will be an update
	---> Package perl-Test-Simple.i686 0:0.92-119.el6_1.1 will be updated
	---> Package perl-Test-Simple.i686 0:0.92-131.el6_4 will be an update
	---> Package perl-devel.i686 4:5.10.1-119.el6_1.1 will be updated
	---> Package perl-devel.i686 4:5.10.1-131.el6_4 will be an update
	---> Package perl-libs.i686 4:5.10.1-119.el6_1.1 will be updated
	---> Package perl-libs.i686 4:5.10.1-131.el6_4 will be an update
	---> Package perl-version.i686 3:0.77-119.el6_1.1 will be updated
	---> Package perl-version.i686 3:0.77-131.el6_4 will be an update
	--> Finished Dependency Resolution

	Dependencies Resolved

	================================================================================
	Package Arch Version Repository Size
	================================================================================
	Installing:
	perl-CPAN i686 1.9402-131.el6_4 updates 245 k
	Installing for dependencies:
	perl-Digest-SHA i686 1:5.47-131.el6_4 updates 61 k
	Updating for dependencies:
	perl i686 4:5.10.1-131.el6_4 updates 9.7 M
	perl-CGI i686 3.51-131.el6_4 updates 208 k
	perl-ExtUtils-MakeMaker i686 6.55-131.el6_4 updates 292 k
	perl-ExtUtils-ParseXS i686 1:2.2003.0-131.el6_4 updates 44 k
	perl-Module-Pluggable i686 1:3.90-131.el6_4 updates 39 k
	perl-Pod-Escapes i686 1:1.04-131.el6_4 updates 31 k
	perl-Pod-Simple i686 1:3.13-131.el6_4 updates 211 k
	perl-Test-Harness i686 3.17-131.el6_4 updates 230 k
	perl-Test-Simple i686 0.92-131.el6_4 updates 111 k
	perl-devel i686 4:5.10.1-131.el6_4 updates 421 k
	perl-libs i686 4:5.10.1-131.el6_4 updates 592 k
	perl-version i686 3:0.77-131.el6_4 updates 50 k

	Transaction Summary
	================================================================================
	Install 2 Package(s)
	Upgrade 12 Package(s)

	Total download size: 12 M
	Is this ok [y/N]: y
	Downloading Packages:
	(1/14): perl-5.10.1-131.el6_4.i686.rpm | 9.7 MB 00:05
	(2/14): perl-CGI-3.51-131.el6_4.i686.rpm | 208 kB 00:00
	(3/14): perl-CPAN-1.9402-131.el6_4.i686.rpm | 245 kB 00:00
	(4/14): perl-Digest-SHA-5.47-131.el6_4.i686.rpm | 61 kB 00:00
	(5/14): perl-ExtUtils-MakeMaker-6.55-131.el6_4.i686.rpm | 292 kB 00:00
	(6/14): perl-ExtUtils-ParseXS-2.2003.0-131.el6_4.i686.rp | 44 kB 00:00
	(7/14): perl-Module-Pluggable-3.90-131.el6_4.i686.rpm | 39 kB 00:00
	(8/14): perl-Pod-Escapes-1.04-131.el6_4.i686.rpm | 31 kB 00:00
	(9/14): perl-Pod-Simple-3.13-131.el6_4.i686.rpm | 211 kB 00:00
	(10/14): perl-Test-Harness-3.17-131.el6_4.i686.rpm | 230 kB 00:00
	(11/14): perl-Test-Simple-0.92-131.el6_4.i686.rpm | 111 kB 00:00
	(12/14): perl-devel-5.10.1-131.el6_4.i686.rpm | 421 kB 00:00
	(13/14): perl-libs-5.10.1-131.el6_4.i686.rpm | 592 kB 00:00
	(14/14): perl-version-0.77-131.el6_4.i686.rpm | 50 kB 00:00
	--------------------------------------------------------------------------------
	Total 1.7 MB/s | 12 MB 00:07
	Running rpm_check_debug
	Running Transaction Test
	Transaction Test Succeeded
	Running Transaction
	Updating : 1:perl-Pod-Escapes-1.04-131.el6_4.i686 1/26
	Updating : 4:perl-libs-5.10.1-131.el6_4.i686 2/26
	Updating : 3:perl-version-0.77-131.el6_4.i686 3/26
	Updating : 1:perl-Pod-Simple-3.13-131.el6_4.i686 4/26
	Updating : 1:perl-Module-Pluggable-3.90-131.el6_4.i686 5/26
	Updating : 4:perl-5.10.1-131.el6_4.i686 6/26
	Updating : 1:perl-ExtUtils-ParseXS-2.2003.0-131.el6_4.i686 7/26
	Updating : perl-Test-Harness-3.17-131.el6_4.i686 8/26
	Updating : 4:perl-devel-5.10.1-131.el6_4.i686 9/26
	Updating : perl-ExtUtils-MakeMaker-6.55-131.el6_4.i686 10/26
	Installing : 1:perl-Digest-SHA-5.47-131.el6_4.i686 11/26
	Installing : perl-CPAN-1.9402-131.el6_4.i686 12/26
	Updating : perl-Test-Simple-0.92-131.el6_4.i686 13/26
	Updating : perl-CGI-3.51-131.el6_4.i686 14/26
	Cleanup : perl-Test-Simple-0.92-119.el6_1.1.i686 15/26
	Cleanup : perl-Test-Harness-3.17-119.el6_1.1.i686 16/26
	Cleanup : perl-ExtUtils-MakeMaker-6.55-119.el6_1.1.i686 17/26
	Cleanup : 1:perl-ExtUtils-ParseXS-2.2003.0-119.el6_1.1.i686 18/26
	Cleanup : 4:perl-devel-5.10.1-119.el6_1.1.i686 19/26
	Cleanup : perl-CGI-3.51-119.el6_1.1.i686 20/26
	Cleanup : 1:perl-Pod-Escapes-1.04-119.el6_1.1.i686 21/26
	Cleanup : 1:perl-Pod-Simple-3.13-119.el6_1.1.i686 22/26
	Cleanup : 3:perl-version-0.77-119.el6_1.1.i686 23/26
	Cleanup : 4:perl-libs-5.10.1-119.el6_1.1.i686 24/26
	Cleanup : 4:perl-5.10.1-119.el6_1.1.i686 25/26
	Cleanup : 1:perl-Module-Pluggable-3.90-119.el6_1.1.i686 26/26 

	Installed:
	perl-CPAN.i686 0:1.9402-131.el6_4 

	Dependency Installed:
	perl-Digest-SHA.i686 1:5.47-131.el6_4 

	Dependency Updated:
	perl.i686 4:5.10.1-131.el6_4
	perl-CGI.i686 0:3.51-131.el6_4
	perl-ExtUtils-MakeMaker.i686 0:6.55-131.el6_4
	perl-ExtUtils-ParseXS.i686 1:2.2003.0-131.el6_4
	perl-Module-Pluggable.i686 1:3.90-131.el6_4
	perl-Pod-Escapes.i686 1:1.04-131.el6_4
	perl-Pod-Simple.i686 1:3.13-131.el6_4
	perl-Test-Harness.i686 0:3.17-131.el6_4
	perl-Test-Simple.i686 0:0.92-131.el6_4
	perl-devel.i686 4:5.10.1-131.el6_4
	perl-libs.i686 4:5.10.1-131.el6_4
	perl-version.i686 3:0.77-131.el6_4 

	Complete!

Note: We no need to install CPAN package in Ubuntu/Debian. By default CPAN package is installed in most Debian machines.

Configuring CPAN

Configuring CPAN first time once it is installed. This is a straight forward step and we can leave it to cpan command to do an automated configuration for you. Just press enter when it asked you for conformation.

	
	cpan

Output:

	
	root@linuxnix.com:/home/surendra# cpan
	Sorry, we have to rerun the configuration dialog for CPAN.pm due to
	some missing parameters. Configuration will be written to
	<</root/.cpan/CPAN/MyConfig.pm>>

	
	CPAN.pm requires configuration, but most of it can be done automatically.
	If you answer 'no' below, you will enter an interactive dialog for each
	configuration option instead.

	Would you like to configure as much as possible automatically? [yes] 

	Autoconfigured everything but 'urllist'.

	Now you need to choose your CPAN mirror sites. You can let me
	pick mirrors for you, you can select them from a list or you
	can enter them by hand.

	Would you like me to automatically choose some CPAN mirror
	sites for you? (This means connecting to the Internet) [yes] 
	Trying to fetch a mirror list from the Internet
	Fetching with LWP:
	http://www.perl.org/CPAN/MIRRORED.BY

	Looking for CPAN mirrors near you (please be patient)
	............................ done!

	New urllist
	http://ftp.carnet.hr/pub/CPAN/
	http://ftp.gwdg.de/pub/languages/perl/CPAN/
	http://ftp.spbu.ru/CPAN/

	Autoconfiguration complete.

	commit: wrote '/root/.cpan/CPAN/MyConfig.pm'

	You can re-run configuration any time with 'o conf init' in the CPAN shell
	Terminal does not support AddHistory.

	cpan shell -- CPAN exploration and modules installation (v1.960001)
	Enter 'h' for help.

	cpan[1]> 

If you observe last few lines of above command output, it say it configured CPAN setting properly and we are presented with cpan prompt. From this prompt we can install any kind of module which is present at cpan.org site.

In our next post we will see how to use cpan command to manage different modules in our machine.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.