LinuxCommandLibrary

cpan

Install and manage Perl modules

TLDR

Install a module (-i is optional)

$ cpan [-i] [module_name]
copy

Force install a module (-i is not optional)
$ cpan -fi [module_name]
copy

Upgrade all installed modules
$ cpan -u
copy

Recompile modules
$ cpan -r
copy

SYNOPSIS

cpan [options] [command [parameters ...]]

PARAMETERS

-a, --local-lib=dir
    Use local::lib in specified directory for user-local installs

-C, --myconfig
    Dump current CPAN configuration

-f, --force
    Force installation (skip failed tests/dependencies)

-F, --save-force-config
    Save config with force and other settings

-g
    Global mode (disable local::lib)

-h, --help
    Display help summary

-i, --immediate
    Run command immediately without confirmation

-r
    Rebuild CPAN index

-S, --cpanhome dir
    Set custom CPAN home directory

-t
    Test module(s) without installing

-T, --notest
    Skip tests during install

-u
    List/update outdated modules

-U, --uptodateall
    Check and update all installed modules

-V
    Enable verbose output

DESCRIPTION

The cpan command is the primary interface to the Comprehensive Perl Archive Network (CPAN), a vast repository of Perl modules and distributions. Included with core Perl, it enables users to search, download, unpack, build, test, and install modules with automatic dependency resolution.

Invoked without arguments, cpan launches an interactive shell supporting commands like install Module::Name, search /regex/, make test, ls authors, and quit. For non-interactive use, run cpan install Foo::Bar directly from the shell.

It configures CPAN mirrors, prerequisites (e.g., make, compilers), and installers like ExtUtils::MakeMaker or Module::Build. First run prompts for configuration via CPAN::Config. Supports local::lib for user-specific installs without root.

While powerful, it can be verbose and slow for large installs. Alternatives like cpanm offer simpler syntax.

CAVEATS

Requires internet and Perl; builds may fail without C compiler or system libraries; root needed for system-wide installs; first run requires interactive config; large dependencies can be time-consuming.

INTERACTIVE COMMANDS

Key commands: install MOD (installs with deps), uninstall MOD, search /pattern/, ls authors/ID/, make/test/clean MOD, reports (recent failures), quit.

CONFIGURATION

Edit ~/.cpan/CPAN/MyConfig.pm; set urllist for mirrors, makepl_arg for install flags, prefer_installer ('mb' or 'eumm'). Use cpan -r to reload.

HISTORY

Developed by Andreas J. König in 1995 as CPAN.pm; integrated into Perl core since Perl 5.004 (1997). Evolved to support modern features like local::lib (2007) and multiple backends.

SEE ALSO

perl(1), cpanm(1), cpanfile(5), CPAN(3pm)

Copied to clipboard