When I first started using CPAN, this was a concern of mine that I was never able to fully address: how do Perl modules from CPAN interact with modules installed via distribution packages?
It turns out that the answer is simple. First, however, let’s install a set of tools called pmtools; these tools will tell you a lot and make it simple. Using these will help you to understand how your system is set up as well. In Ubuntu, the package is called pmtools; in Red Hat, it is perl-pmtools. To install, use this command on an Ubuntu system as root:
$ sudo apt-get install pmtools
On a Red Hat Enterprise Linux system, use this command instead:
$ sudo yum install perl-pmtools
Once that is installed, use the tool pmdirs to see what directories are searched for modules in order. Here is one example from an Ubuntu 10.04 LTS server system:
$ pmdirs /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .
With this, you can see that several site-specific directories in /usr/local are searched before system directories in /usr.
Same thing holds true for Red Hat; here is an example from a Red Hat Enterprise Linux 5.7 system:
$ pmdirs /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .
In Red Hat, system-installed Perl modules go into
/usr/lib/perl5/vendorperl/$version/ while modules installed with CPAN go into
perl/$version/. On the other hand, in Ubuntu, CPAN modules go into
/usr/local/share/perl5/$version/ while packaged modules are placed in
This means that modules installed with CPAN will be searched (and found) first – whether they are newer or not. Usually they will be newer, but if they are the same version you’re better off staying with the packaged version of the Perl module as it will often have bugfixes and patches not present on the original.
If you want to see where a particular module lives – use
$ pmpath CPAN /usr/local/share/perl/5.10.1/CPAN.pm
This shows that CPAN was installed from (or updated from) CPAN as well.
If you want to see what version is installed, use
$ pmvers CPAN 1.9600
Note: In Ubuntu you may find that the directory
/usr/local/lib/site_perl is missing and that some pmtools utilities will fail because of this. Use this command to create the directory (and stop the error messages):
# mkdir -p /usr/local/lib/site_perl