Manage CPAN Modules with cpanminus

Updated by Linode Written by Linode

Contribute on GitHub

Report an Issue | View File | Edit File


CPAN, the Comprehensive Perl Archive Network, is the primary source for publishing and fetching the latest modules and libraries for the Perl programming language. The default method for installing Perl modules, using the CPAN Shell, provides users with a great deal of power and flexibility, but this comes at the cost of a complex configuration and an inelegant default setup.

The cpanm client attempts to make the power of CPAN accessible to all users, particularly those who aren’t Perl developers, but have experience with the CPAN shell. This document outlines the procedures for installing cpanminus and demonstrates a number of basic use cases. If you’re new to the world of Linux systems administration, you may want to review our introduction to Linux concepts guide and administration basics guide before completing this guide.

Install Dependencies

  • Debian and Ubuntu:

    apt-get update
    apt-get upgrade
    apt-get install perl build-essential libssl-dev
  • CentOS and Fedora:

    yum update
    yum install perl perl-devel curl gcc

Install cpanminus

  1. Curl the latest cpanminus and use it to bootstrap itself:

    curl -L | perl - --sudo App::cpanminus
  2. Update cpanminus:

    cpanm --self-upgrade --sudo

Use cpanminus

Basic Usage

The basic syntax to install a module with cpanminus is:

cpanm [Module::Name]

By default, Perl modules will be installed to ~/perl5 rather than the more customary /usr/local/bin directory. This will cause a warning during the installation process. You can avoid this warning by adding the --sudo option, which will run the installation with root privileges and install to /usr/local/bin. If you would like to continue installing Perl modules to ~/perl5 without the warning, use the following command:

cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)

Skip Installed

You can also use the --skip-installed option to avoid reinstalling modules when the latest version is already installed. Consider the following example:

cpanm --sudo --skip-installed Catalyst::Runtime Class::Inspector

This installs the specified modules to the system location (with --sudo), but only if they haven’t been installed already.

Install from Remote URL

You can also specify the url of a Perl module and CPAN will fetch the module from that location, build the dependencies, and install it:

cpanm --sudo
You may need to run cpanm Net::SSLeay first in order to request a url with https.

Get Package Information

Use the --info option to view information regarding a package in CPAN:

cpanm --info [Module::Name]

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.