Skip to content

Perl CPAN Guide — Module Installation, cpanm, and Dependency Management

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about Perl CPAN Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Perl CPAN is the largest module Repository with over 200,000 distributions -- accessible through cpan (interactive shell), cpanm (fast zero-config), and local::lib (user-level installs without root) for dependency management.

Installing Modules

# Using cpanminus (recommended)
cpanm Module::Name
cpanm DBI Moose Plack

# Using cpan shell
cpan
cpan[1]> install Module::Name

# Force install
cpanm --force Module::Name

# Skip tests
cpanm --notest Module::Name

Managing Dependencies

# Check installed modules
cpanm --info Module::Name

# List installed modules
cpan -l

# Update modules
cpan -u

# Check for outdated
cpan -O

local::lib

# Install local::lib first
cpanm local::lib

# Set up local library
perl -Mlocal::lib=~/perl5

# Add to shell profile
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> ~/.bashrc

# Now install modules locally
cpanm DBI  # installs to ~/perl5

Carton for Applications

# cpanfile
requires 'Mojolicious', '>= 9.0';
requires 'DBIx::Class';
recommends 'Starman';

on 'test' => sub {
    requires 'Test::More';
};
# Install dependencies
carton install

# Run with carton's perl
carton exec perl app.pl

# Update snapshot
carton install --deployment

Common Mistakes

1. Installing with root when not needed

Use local::lib for user installs. Don't run cpanm as root unless necessary.

2. Ignoring test failures

If module tests fail, the module may not work correctly. Check the error output, don't force install blindly.

3. Not using cpanfile for projects

A cpanfile documents dependencies. Without it, deploying to a new system requires remembering what modules to install.

Practice Questions

1. What is the recommended way to install CPAN modules? cpanm (cpanminus) -- zero configuration, auto-resolves dependencies, and installs modules.

2. How do you install modules without root? Use local::lib: perl -Mlocal::lib=~/perl5 then cpanm installs to that directory.

3. What is a cpanfile? A file listing module dependencies for a project, readable by Carton, cpanm, or cpan.

FAQ

{{< faq question="What is the difference between cpan and cpanm?" >}} cpan is the interactive CPAN shell. cpanm (App::cpanminus) is a lightweight, zero-config alternative that's faster and easier to use. {{< /faq >}}

{{< faq question="How do I find modules on CPAN?" >}} Search on metacpan.org or use cpanm -S Module::Name to search module names. {{< /faq >}}

{{< faq question="Can I install specific versions?" >}} Yes: cpanm Module::Name@1.23 installs a specific version. Carton locks versions in cpanfile.snapshot. {{< /faq >}}

What's Next

Now learn about Unicode support in Perl.

Topic Description Link
Unicode Unicode and encoding {{< ref "26-unicode" >}}
Signals Signal handling {{< ref "28-signals" >}}

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro