Manage CPAN Modules with cpanminus

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

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 https://cpanmin.us | 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 https://cpan.metacpan.org/authors/id/O/OL/OLIVER/App-Netdisco-2.036011.tar.gz
Note
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.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.