Five ways to install module prereqs by hand

Have you ever tried installing a CPAN module's dependencies by hand? Imagine that you've downloaded a strange tarball or cloned a strange module repository. Running "perl Makefile.PL" or "perl Build.PL" gives you a long list of missing dependencies. How do you quickly install all those dependencies?

Here are some options. See the last for a new way that I just cooked up and released to CPAN.

Use your favorite CPAN client against the current directory


$ cpan .

Beware that this also installs the module in the current directory, which may not be what you want.

cpanminus is smarter than that if you give it an option

$ cpanm --installdeps .

For Module::Build-based modules: Build installdeps


$ perl Build.PL
$ Build installdeps

For (some) Module::Install-based modules: make installdeps


$ perl Makefile.PL
$ make installdeps

Note that this requires the Makefile.PL to use the 'auto_install' plugin.

For Dist::Zilla-based modules: dzil listdeps


$ dzil listdeps | cpanm
# or
$ cpan $(dzil listdeps)

This requires installing Dist::Zilla any any dist.ini dependencies first:

$ cpanm Dist::Zilla
$ dzil authordeps | cpanm

(Notice a pattern here?)

Anything with Makefile.PL or Build.PL: MYMETA and mymeta-requires

Install the latest ExtUtils::MakeMaker, Module::Build and App::mymeta_requires. Then configure as usual and run 'mymeta-requires' to get a list of dependencies.


$ perl Makefile.PL
$ mymeta-requires | cpanm
# or
$ cpan $(mymeta-requires)

A nice feature of 'mymeta-requires' is that it gives you access to all the different prerequisite types defined in the CPAN::Meta::Spec. So if a module offers 'develop' prerequisites, you can include those like this:

$ mymeta-requires --develop | cpanm

See the documentation for other ways to control which prerequisites are included in the output.

One drawback is that you'll still need to install any configuration prerequisites needed to run Makefile.PL or Build.PL, but that is true of all other recipes above (except that ones that use a CPAN client).

Update: as of version 0.002, 'mymeta-requires' will fallback to a META.json|yml file and also picks up configuration prerequisites. So now you can bootstrap completely like this:

# get configuration prerequisites
$ mymeta-requires | cpanm

# run configuration
$ perl Makefile.PL

# get any additional dynamic prerequisites from configuration
$ mymeta-requires | cpanm


This entry was posted in perl programming, toolchain and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Posted August 14, 2011 at 8:55 am | Permalink

    "Have you ever tried installing a CPAN module's dependencies by hand?"

    Yes, back in the days when I had to compile Perl by hand. Try installing XML::Parser and compiling the Expat library by hand. It' a treat, not. These days I don't bother. If cpan fails, I whine and bitch until someone fixes it. :)

  2. Mark Grimes
    Posted August 25, 2011 at 9:36 am | Permalink

    One more option to add to the list. If you are a cpanp user, there is a plugin that adds the /prereqs command.

    First, install the plugin:

    $ cpanp i CPANPLUS::Shell::Default::Plugin::Prereqs

    Then use the /prereqs command:

    # Install the prereqs for the project in the cwd:
    $ cpanp /prereqs install .
    # Show the prereqs for any module:
    $ cpanp /prereqs show Moose

    See the docs for CPANPLUS::Shell::Default::Plugin::Prereqs for more details.

    I'm the plugin author, so this has been a shameless plug. To be honest, I've been using cpanm quite a bit lately. My one complaint about cpanm (which brings me back to cpanp and this plugin) is that cpanm lacks integration with Test::Reporter.

    • Posted August 25, 2011 at 10:13 am | Permalink

      I have no problem with shameless plugs. Thanks for pointing out another way to do it!

  3. Luke Patterson
    Posted May 17, 2012 at 4:35 pm | Permalink

    Goodness. Thanks!

2 Trackbacks