iServerSupport Talk to an engineer

How to List Installed Perl Modules on Your Server

List installed Perl modules with cpan -l, ExtUtils::Installed, instmodsh, perllocal or an @INC search, and fix Can't locate Module.pm in @INC.

Package box icon representing installed Perl modules on a Linux server

Sooner or later a script fails on a server with a message about a module Perl cannot find, and the first question is what is actually installed. The honest answer is that there is no single command that lists everything. Perl modules reach a server in several ways: from CPAN, from the operating system's package manager, bundled with Perl itself, or dropped into a private directory. Each listing method sees some of those routes and misses the rest. This guide shows the commands that work, what each one misses, and how to answer the more useful question of whether one particular module is available.

First, find out which Perl you are asking

Servers often have more than one Perl, and the list you get depends entirely on which one answers. Check what runs by default and where it looks for modules:

which -a perl
perl -v | head -2
perl -e 'print "$_\n" for @INC'

The last command prints the directories Perl searches, in order. This matters on cPanel servers in particular, where cPanel ships its own Perl for its internal tools at /usr/local/cpanel/3rdparty/bin/perl, separate from the system Perl in /usr/bin/perl. A module can exist for one and not the other, which is a classic cause of "it works in my shell but not in the script". Perl managers such as perlbrew add further interpreters. Whatever command you use below, run it with the same Perl that your failing script uses.

Method 1: cpan -l

The quickest listing on most servers is the cpan command with the list flag:

cpan -l

It prints each installed module with its version. It reads from the installed copies on disk, so it also sees modules that came from sources other than CPAN. If cpan is missing, it ships with Perl itself or in a separate package called perl-CPAN on RPM-based systems.

You will sometimes see advice to open the CPAN shell with perl -MCPAN -e shell and type m. That command searches the CPAN index and does not list what is installed on your machine, so it is the wrong tool for this job. Inside the shell, the useful command is r, which reports installed modules that have a newer release available.

Method 2: ExtUtils::Installed

For a scriptable list, ask Perl directly:

perl -MExtUtils::Installed -e 'print "$_\n" for ExtUtils::Installed->new->modules'

This works from the packing lists that installers leave behind, so it can miss modules that were installed without one. That includes many modules installed by operating system packages. Treat it as a good list, not a complete one.

Method 3: instmodsh

Perl includes an interactive tool built on the same library:

instmodsh

At its prompt, l lists modules, m Module::Name selects one, and f then lists the files it installed, which is useful when you need to know exactly what a module put on the disk. It shares the packing-list limitation of the previous method.

Method 4: perldoc perllocal

perldoc perllocal

This shows a record of modules installed through the standard build tools, with dates and installation details. It only includes modules that wrote to that file, so packages installed with apt, dnf or yum normally do not appear. It is handy for seeing what was added by hand over the years and misleading as a full inventory.

Method 5: search the module path itself

The most complete answer comes from looking at the files. The Perl FAQ, in its section on finding installed modules, suggests walking every directory Perl searches:

perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

This prints the path of every .pm file Perl can load, whatever installed it, so nothing is hidden by bookkeeping. The output is long, since it includes the core library. Pipe it through grep or wc -l when you only want a count or a specific name.

Package manager listings

If the module came from your distribution, the package manager knows about it. Distribution packages follow a naming convention: libjson-perl style names on Debian and Ubuntu, and perl-JSON style names on RPM-based systems.

dpkg -l | grep -i -E '^ii +lib.*-perl'
rpm -qa 'perl-*' | sort

The Debian command lists installed packages ending in -perl, and the RPM one lists the Perl packages. These listings show exactly what the OS manages, which is what you want when planning updates.

Check one module instead of listing everything

Most of the time you do not need the full list. You need to know whether a specific module exists and which version it is:

perl -MSome::Module -e 'print Some::Module->VERSION, "\n"'
perldoc -l Some::Module

The first prints the version, or an error if the module cannot be loaded. The second prints the file path, which tells you which copy Perl is picking up, valuable when several versions exist. To find out whether a module ships with Perl itself, and from which release, use corelist Some::Module.

Fixing "Can't locate Module.pm in @INC"

This is the error that sends most people to this page. It reads like Can't locate Some/Module.pm in @INC (you may need to install the Some::Module module), followed by the list of directories searched. It means Perl looked in every directory it knows and found no such file. Work through three possibilities in order.

The script is using a different Perl

The script runs under a different interpreter from the one you tested with. Compare which -a perl with the first line of the script, and run the version check above with that same interpreter.

The module is genuinely missing

Install it, preferably from your operating system so that updates are managed with everything else. Ask the package manager which package provides it:

dnf provides 'perl(Some::Module)'
apt-file search Some/Module.pm

Install the package it names, for example perl-Some-Module on RPM-based systems or libsome-module-perl on Debian. If the module is not packaged for your system, install it with cpan Some::Module. On a cPanel server, prefer the panel's own module installer or your distribution's package over a plain CPAN install, since a module installed for the wrong Perl leaves the error in place.

The module is installed where Perl does not look

A module installed into a user's home directory, for instance with local::lib, is invisible to a service running as another user. Fix it by installing system-wide, or by pointing the script at the right directory with use lib or the PERL5LIB variable.

Keep modules tidy over time

A few habits prevent most surprises. Prefer distribution packages for system-wide modules and CPAN only for things your system does not package. Use cpan -u sparingly on production servers, as it upgrades every module and can change behavior your applications depend on, so test it first. Keep a record of which modules your applications need. And treat Perl updates as part of regular maintenance, as in our Linux server maintenance checklist.

If Perl scripts are failing after an update on a cPanel server, our guides on WHM package updates failing and cPanel 500 internal server errors cover related causes.

If a server is stuck on a module or package problem and you would rather have an engineer sort it out safely, our Linux server management team can help, and you can contact us with the error and the server details.

Linux server management

Perl modules missing or conflicting on your server?

Our Linux engineers sort out Perl, cPanel and package problems on servers you already run, without breaking what works.