Perl modules are reusable packages of Perl code that can be integrated into your existing Perl program to perform specific tasks. They may depend on other Perl modules to function properly, in which case both modules should be installed.

The Comprehensive Perl Archive Network (CPAN) is the largest repository for storing around 200,000+ Perl modules, most of which require the latest Perl version, so ensure Perl installed on your system is up-to-date.

To install Perl modules from CPAN, you need a command program, and there are three well-known and popular command-line programs: CPAN CLI, CPAN PLUS, and CPAN MINUS, that you can use for this purpose.

  • CPAN CLI: It's been included in the Perl package (Since 1997) and guides you through a few questions upon first launch. After that, you can start installing modules by running the cpan -i Module::Name command.
  • CPAN PLUS: It was an incomplete program that began with the intention of becoming a newer, better, and more featureful CPAN command program.
  • CPAN MINUS: It's a simple tool that sidesteps the hassle of the default CPAN CLI, allowing you to easily install Perl modules using the cpanm Module::Name command.

The CPAN CLI is widely used and comes preinstalled with Perl. However, in this article, I'll show you how to install and use CPAN MINUS on Ubuntu 24.04, 23.04, and other versions.

Install Perl Modules on Ubuntu 24.04 and Other

Prior to installation, make sure to update the package database by running:

$ sudo apt update

Output:

updating package database

Install the latest version of Perl:

$ sudo apt install perl

Output:

installing perl on ubuntu

Verify the installation by checking the Perl version:

$ perl -v

Output:

checking perl version

Install the CPAN MINUS package for installing Perl modules from CPAN.

$ sudo apt install cpanminus

Output:

installing perl module on ubuntu

Let's install a Net::DNS Perl module from CPAN using CPAN MINUS.

$ sudo cpanm Net::DNS

Output:

install perl module from CPAN on ubuntu

List All Perl Modules on Ubuntu 24.04 and Other

The perldoc (required installation) and instmodsh can be used to list all installed Perl modules from CPAN.

$ perldoc perllocal

# OR

$ instmodsh

Output:

list installed perl modules

However, the method above won't list Perl modules that are manually or pre-installed with your Linux distribution. To list them, you can use the following two commands:

$ cpan -l

# OR

$ cpan -a

Output:

listing all manually and preinstalled perl modules

Uninstall Perl Modules from Ubuntu 24.04 and Other

You can uninstall your desired Perl modules by running:

$ sudo cpanm --uninstall Net::DNS

It will ask for confirmation, press Enter to continue.

uninstall perl modules from ubuntu

Uninstall CPAN MINUS and Perl from Ubuntu 24.04 and Other

Finally, remove the CPAN MINUS and Perl itself by running:

$ sudo apt remove --purge cpanminus
$ sudo apt remove --purge perl