How to install CPAN modules
Here are some recommended approaches to installing modules from CPAN, as
with much of Perl there are several alternatives.
Some basics
Most Perl modules are written in Perl, some use XS (they are written in C) so require a
C compiler (it's easy
to get this setup - don't panic), see your OS of choice below to find out how
to get the right compiler. Modules may have dependencies on other modules
(almost always on CPAN) and cannot be
installed without them (or without a specific version of them). It is worth
throughly reading the documentation for the options below. Many modules on
CPAN require a somewhat recent version of Perl (version 5.8 or above).
Quick start
Install cpanm to make installing other modules easier (you'll
thank us later). You need to type these commands into a Terminal emulator
(macOS,
Win32, Linux)
cpan App::cpanminus
Now install any module you can find.
cpanm Module::Name
Tools
To help you install and manage your modules:
local::lib enables
you to install modules into a specified directory, without requiring root
or administrator access. See the
bootstrapping technique for how to get started. You can create a
directory per user/project/company and deploy to other servers, by copying the directory
(as long as you are on the same operating system and perl version).
cpanm from
App::cpanminus is
a script to get, unpack, build and install modules from CPAN. It's
dependency free (can bootstrap itself) and requires zero configuration
(install
instructions). It automates the entire build process for the majority
of modules on CPAN and works well with local::lib and
perlbrew. Many experienced Perl developers use this as their tool
of choice. Related tools: cpan-outdated,
pm-uninstall,
cpan-listchanges.
perlbrew
from App::perlbrew
is useful if your system perl is too old to support modern CPAN modules, or
if it's troublesome in other capacities (RedHat/CentOS are included in this
list). perlbrew makes the process of installing a Perl in any directory
much easier, so that you can work completely independently of any system
Perl without needing root or administrator privileges. You can use multiple
versions of Perl (maybe as you upgrade) across different projects. The
separation from your system Perl makes server maintenance much easier and
you more confident about how your project is setup. Currently
Windows is not supported.
cpan
from CPAN has been
distributed with Perl since 1997 (5.004). It has many more options than
cpanm, it is also much more verbose.
cpanp
from CPANPLUS had been
distributed with Perl since 5.10 (2007) until 5.20 (2014). This offers even more options
than cpanm or cpan and can be installed just like cpanminus.
Perl on Windows (Win32 and Win64)
Strawberry Perl is an open source
binary distribution of Perl for the Windows operating system. It includes a
compiler and pre-installed modules that offer the ability to install XS
CPAN modules directly from CPAN. It also comes with lots of modules
pre-installed, including cpanm.
ActiveState
provide a binary distribution of Perl (for many platforms), as well as their
own perl
package manager (ppm). Some modules are not available as ppm's
or have reported errors on the ppm build system, this does not mean
they do not work. You can use the cpan script to build modules
from CPAN against ActiveState Perl.
Perl on macOS
macOS comes with Perl pre-installed. in order to build and install your
own modules you will need to install the "Command Line Tools for XCode"
or Xcode package -
details on our
ports page.
Once you have done this you can use all of the tools mentioned above.
Perl on other Unix like OSs
Install 'make' through your package manager. You can then
use all of the tools mentioned above.
Other tools
CPAN::Mini can provide
you with a minimal mirror of CPAN (just
the latest version of all modules). This makes working offline easy.
CPAN::Mini::Inject
allows you to add your own modules to your local CPAN::Mini mirror of CPAN.
So you can install and deploy your own modules through the same tools you
use for CPAN modules.
Which modules should I use?
Task::Kensho lists
suggested best practice modules for a wide range of tasks. https://metacpan.org/ will let you search
CPAN. You could also get involved with the community, ask on a mailing list or find your nearest Perl Mongers group.