In this article we will learn How to Install Perl Modules Using CPAN on CentOS 8. The Comprehensive Perl Archive Network (CPAN) is a central repository of currently 188,714 Perl modules in 40,986 distributions. It is a single location where you can find, download and install any of the Perl libraries. It has 25,000 modules available and it is mirrored on servers around the world. It also supports automated testing cross-platform and on multiple versions of Perl, and bug tracking for every library.
The CPAN Perl module is a core module that allows you to query, download, build and install Perl modules and extensions from CPAN sites. It has been distributed with Perl since 1997 (5.004). It includes some primitive searching capabilities and supports named and versioned bundles of modules.
To use CPAN we first need to install perl-CPAN package. Install it using the following command:
dnf install perl-CPAN
Most Perl modules are written in Perl, some use XS – they are written in C and so require a C compiler which is included in the Development Tools package. Use the following command to install Development tools package.
dnf install "@Development Tools"
How to Install Perl Modules Using CPAN:
To install Perl modules using CPAN, you need to use the cpan command-line utility. You can either run cpan with arguments from the command-line interface, for example, to install a module use the -i flag as shown below:
cpan -i Geo::IP
When you run cpan for the first time, it requires configuration as shown in the screenshot below. For this guide, we will enter yes to configure it automatically. If you enter no , the configuration script will take you through a series of questions to configure it.
Now CPAN will install Geo::IP module.
Also, you can install per modules from CPAN shell. To enter CPAN shell use the following command:
cpan
Now as an example we will install Log::Log4perl module to show you the installation via CPAN Shell.
install Log::Log4perl
To leave cpan shell type exit and press enter
We can also list the installed perl modules using the following command:
cpan -l
Search a Perl Module Using CPAN:
To search a module, enter into the cpan shell and use the following command:
cpan
m Net::Telnet
CPANM is another popular module used to download, unpack, build and install modules from CPAN. To get it working on your system, install the CPANM module using the following command:
cpan App::cpanminus
CPANM is now installed. You can now install module using CPANM. As an example we will install a module using the following command:
cpanm Net::Telnet
We have Installed CPAN and CPANM and Illustrated their use with some examples as well. You can now use it according to your need.