Perl is a well-known programming language with long development history. The same long history provides the countless modules written in it, and distributed in various channels throughout the World Wide Web. As with most programming languages, if you implement something that you find useful, and maybe write it in a generic way, there are high chances others would find it useful too.
If you share your work with others, they don’t need to re-implement the wheel, they can spend time on other tools, thus making the community as a whole richer, and we have found the spirit of open source with a short walk. But as many people write perl modules, and perl runs on just about anything, it can be hard to find the module you are looking for, let alone build it in your environment. And that’s where
cpan comes into play. CPAN itself is a large perl module repository, the
cpan tool is a client that is able to fetch and compile needed modules to the local system.
In this tutorial we’ll install
cpan on a RHEL 8 / CentOS 8, run the initial configuration, and install a module with this tool’s help.
In this tutorial you will learn:
- How to install cpan
- How to run initial configuration
- How to install a perl module with cpan
Software Requirements and Conventions Used
|Category||Requirements, Conventions or Software Version Used|
|System||RHEL 8 / CentOS 8|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install cpan on RHEL 8 / CentOS 8 step by step instructions
rpm package of
cpan is present in the software sources after enabling subsription management repositories.
While it’s name is a bit tricky at first, after a few encounters with perl packages we’ll get used to the naming convention, and it can come quite handy to query the rpm database for
perl-* pattern when we search for something written in perl. But that’s the realm of
- We can install package
# dnf install perl-CPAN
- Before we can start using our new tool, we need to run the initial configuration. At version 2.18 it is pretty automatic if we choose to.
# cpan [...] 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] yes [...]
In the output we can see that the autoconfiguration creates needed default directories and configuration files. We can always re-run this step if needed with
'o conf init'provided to the CPAN shell (which is what we’ll use in the next step).
- When the configuration is complete, we arrive at to the CPAN shell, where we can directly enter commands to cpan. To test our tool we will install the
Config::Tinyperl module, which can be familiar to anyone as “missing” who ever worked with perl-based Nagios plugins.
cpan> install "Config::Tiny" Fetching with HTTP::Tiny: http://www.cpan.org/authors/01mailrc.txt.gz Reading '/root/.local/share/.cpan/sources/authors/01mailrc.txt.gz' ............................................................................DONE Fetching with HTTP::Tiny: http://www.cpan.org/modules/02packages.details.txt.gz Reading '/root/.local/share/.cpan/sources/modules/02packages.details.txt.gz' [...] Running make install Manifying 1 pod document Installing /usr/local/share/perl5/Config/Tiny.pm Installing /usr/local/share/man/man3/Config::Tiny.3pm Appending installation info to /usr/lib64/perl5/perllocal.pod RSAVAGE/Config-Tiny-2.23.tgz /usr/bin/make install -- OK cpan> exit
After some work,
cpancompletes the module installation, and with that we verified our tool is working as intended. We can leave the CPAN shell with
exit, or enter another command, maybe installing more needed modules.