This brief guide explains how to install Perl modules on Linux from CPAN (Comprehensive Perl Archive Network) repository. As of writing this guide, there are 185,128 Perl modules available in CPAN. Many programs written in Perl programming language depends on certain perl modules to perform a specific task. For example, the other day I was testing Sysadmin-util which provides a collection of useful tools for Linux/Unix sysadmins. When I test a specific tool called multi-ping, I encountered with the following error:
$ ./multi-ping google.com The required Net::DNS module is missing. Aborting.
In such cases, you need to find and install the missing perl module in order to use that program.
Install Perl Modules On Linux
There are many tools available to install and Perl modules. We are going to try two tools namely cpan and cpanm. It is worth mentioning that Many modules on CPAN requires the recent version of Perl version 5.8 or above.
Please ensure that you have installed 'make' package on your Linux distribution. 'make' is an essential tool for building perl Modules.
If you don't install 'make', you might encountered with an error something like below:
Can't configure the distribution. You probably need to have 'make'.
'make' package is available in the default repositories most Linux distributions.
To install 'make' on Arch Linux and its variants, run:
$ sudo pacman -S make
On Debian, Ubuntu, Linux Mint:
$ sudo apt install make
$ sudo dnf install make
On RHEL, CentOS:
$ sudo yum install make
$ sudo zypper install make
Let us go ahead and install perl modules.
Install Perl modules using cpan
cpan is a command line client for CPAN repository and is distributed with all Perl editions by default.
To install a Perl module, for example Net::DNS, enter into cpan shell using command:
$ sudo cpan
And type the following command from cpan prompt to install the module:
Once the module is installed, type 'exit' to return back to your shell.
You can also directly install the module from the Terminal using command:
$ sudo cpan Net::DNS
Install Perl modules using Cpanminus
Cpanminus or cpanm is a cpan client to get, unpack, build and install modules from CPAN repository. It is a standalone, dependency-free script that requires zero-configuration. Many experienced Perl developers prefer cpanm over cpan.
cpanminus can be installed in many ways.
1. Using Perl:
To install latest cpanm version on your Linux system, just run:
$ curl -L https://cpanmin.us | perl - --sudo App::cpanminus
This command will install cpanm system-wide and install cpanm binary to your bin directory like /usr/local/bin.
2. Using distribution's package manager:
cpanm is also available in the default repositories of several Linux distributions. It is stable version, but bit old.
To install cpanminus on Arch Linux and its variants, run:
$ sudo pacman -S cpanminus
On Debian, Ubuntu, Linux Mint:
$ sudo apt install cpanminus
$ sudo yum install perl-App-cpanminus
3. Manual installation:
Alternatively, you can manually download latest cpanm binary and put it in your $PATH like below.
$ curl -L https://cpanmin.us/ -o cpanm
$ chmod +x cpanm
$ sudo mv cpanm /usr/local/bin/cpanm
After installing cpanm, you can install any Perl modul, for example Net::DNS, by running the following command from your Terminal:
$ sudo cpanm Net::DNS
--> Working on Net::DNS Fetching http://www.cpan.org/authors/id/N/NL/NLNETLABS/Net-DNS-1.21.tar.gz ... OK Configuring Net-DNS-1.21 ... OK ==> Found dependencies: Digest::HMAC --> Working on Digest::HMAC Fetching http://www.cpan.org/authors/id/G/GA/GAAS/Digest-HMAC-1.03.tar.gz ... OK Configuring Digest-HMAC-1.03 ... OK Building and testing Digest-HMAC-1.03 ... OK Successfully installed Digest-HMAC-1.03 Building and testing Net-DNS-1.21 ... OK Successfully installed Net-DNS-1.21 2 distributions installed
Install missing Perl modules using distribution's package manager
Many Perl modules are available as packages, so you can install it using your distribution's package manager.
On Debian, Ubuntu:
$ apt-cache search 'perl$' | grep Net::DNS
libnet-dns-zonefile-fast-perl - fast BIND-style zonefile parser on top of Net::DNS
As you can see, the Net::DS module is provided by "libnet-dns-zonefile-fast-perl", so let us install it using command:
$ sudo apt install libnet-dns-zonefile-fast-perl
To find the missing module on Arch Linux, run:
$ pacman -Ss '^perl-' | grep Net::DNS
And install the missing module using 'pacman' command.
List installed Perl modules
To list the installed Perl modules, use 'perldoc' command:
$ perldoc perllocal
Thu Jan 30 10:45:11 2020: "Module" Digest::HMAC * "installed into: /usr/local/share/perl/5.26.1" * "LINKTYPE: dynamic" * "VERSION: 1.03" * "EXE_FILES: " Thu Jan 30 10:47:41 2020: "Module" Net::DNS * "installed into: /usr/local/share/perl/5.26.1" * "LINKTYPE: dynamic" * "VERSION: 1.21" * "EXE_FILES: " Thu Jan 30 10:48:54 2020: "Module" Digest::BubbleBabble * "installed into: /usr/local/share/perl/5.26.1" * "LINKTYPE: dynamic" * "VERSION: 0.02" * "EXE_FILES: "
Another way to list the installed Perl modules is to use 'instmodsh' command like below.
You will see the following output:
Available commands are: l - List all installed modules m <module> - Select a module q - Quit the program cmd?
In cmd prompt, type 'l' to list the modules.
Installed modules are: App::cpanminus Digest::BubbleBabble Digest::HMAC Module::Build Net::DNS Perl cmd?
Please note that the above two commands will list the modules installed with cpan. There could be many modules installed either manually or pre-installed with your Linux distribution.
To find all installed Perl modules, run:
$ cpan -l
$ cpan -a
Uninstall Perl modules
The Perl modules can be easily removed using cpanm using command:
$ sudo cpanm --uninstall Net::DNS
Type y and hit ENTER to remove the module long with all configuration files.
Net::DNS contains the following files: /usr/local/man/man3/Net::DNS.3pm /usr/local/man/man3/Net::DNS::Domain.3pm /usr/local/man/man3/Net::DNS::DomainName.3pm [...] /usr/local/share/perl/5.26.1/Net/DNS/Text.pm /usr/local/share/perl/5.26.1/Net/DNS/Update.pm /usr/local/share/perl/5.26.1/Net/DNS/ZoneFile.pm Are you sure you want to uninstall Net::DNS? [y] y
Hope this helps.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!