[[!meta title="Using CPAN"]] [CPAN](http://cpan.org) is the "Comprehensive Perl Archive Network", a repository of useful Perl modules. Most projects written in Perl depend on at least one module from CPAN, and dependency graphs of dozens of modules are not uncommon. Unfortunately, installing CPAN modules can be somewhat tricky, in part due to the age of many of the tools involved. This document is designed to help someone who is not a Perl programmer learn how to get a CPAN module or set of modules installed with a minimum of pain. ## Is it in my distribution? Most popular Linux distributions package a large number of CPAN modules as part of the distribution. If a sufficiently new version of the package you want is available from your distribution, this is likely to be a better option than installing it from CPAN. If you are running Debian or Ubuntu, the Perl module `Foo::Bar` will be present, if at all, under the name `libfoo-bar-perl`. On Fedora, it will be named `perl-Foo-Bar`, or can be found with the query yum whatprovides 'perl(Foo::Bar)' ## The short version (installing packages system-wide) If you want some more explanation, skip to the next section. This section is meant as a cheat-sheet for people who just want to remember the various incants. This assumes you want to install packages system-wide on the local system, and are a sudoer. $ env PERL_MM_USE_DEFAULT=1 cpan cpan> o conf make_install_make_command '/usr/bin/sudo /usr/bin/make' cpan> o conf mbuild_install_build_command '/usr/bin/sudo ./Build' cpan> o conf prerequisites_policy follow cpan> o conf commit cpan> install Some::Module ## Installing packages system-wide The easiest way to use CPAN is to install packages system-wide. Run `cpan` as your user, and then enter the following commands to configure CPAN to use `sudo` to get root privileges to install packages: o conf make_install_make_command '/usr/bin/sudo /usr/bin/make' o conf mbuild_install_build_command '/usr/bin/sudo ./Build' o conf commit You should now be able to install a package with `install Package`. ## Automatically installing dependencies By default, CPAN prompts you whether or not to follow dependencies when installing a package. This is not usually what you want -- if you want a specific package, you don't care what CPAN has to install to get it to you, so it should do so automatically. There are two steps required to get CPAN to do this: * Set `prerequisites_policy` to `follow` inside CPAN (`o conf prerequisites_policy follow` and then `o conf commit`) * Set the environment variable `PERL_MM_USE_DEFAULT` to `1`. e.g. run `cpan` as `env PERL_MM_USE_DEFAULT=1 cpan`