How do I tell CPAN to install all dependencies?

100,916

Solution 1

Here is the one-liner making these changes permanent including automatic first-time CPAN configuration:

perl -MCPAN -e 'my $c = "CPAN::HandleConfig"; $c->load(doit => 1, autoconfig => 1); $c->edit(prerequisites_policy => "follow"); $c->edit(build_requires_install_policy => "yes"); $c->commit'

Or combine it with local::lib module for non-privileged users:

perl -MCPAN -Mlocal::lib=~/perl5 -e 'my $c = "CPAN::HandleConfig"; $c->load(doit => 1, autoconfig => 1); $c->edit(prerequisites_policy => "follow"); $c->edit(build_requires_install_policy => "yes"); $c->commit'

Run it before using the CPAN shell or whatever.

Solution 2

Try setting PERL_MM_USE_DEFAULT like so:

PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'

It should make CPAN answer the default to all prompts.

Solution 3

The latest and greatest answer to this question is to use cpanm instead (also referred to as App::cpanminus or cpanminus)!

DESCRIPTION

cpanminus is a script to get, unpack, build and install modules from CPAN and does nothing else.

It's dependency free (can bootstrap itself), requires zero configuration, and stands alone. When running, it requires only 10MB of RAM.

To bootstrap install it:

curl -L http://cpanmin.us | perl - --sudo App::cpanminus

or if you are using perlbrew simply

perlbrew install-cpanm

or from cpan itself:

cpan install App::cpanminus

From then on install modules by executing (as root if necessary)

cpanm Foo::Bar

Solution 4

Changing the following parameter on top of prerequisites_policy follows.

cpan> o conf prerequisites_policy 'follow'
cpan> o conf build_requires_install_policy yes
cpan> o conf commit

This will change it from "ask/yes" to "yes" and stop it asking you.

Solution 5

Here's what I'm pretty sure you're looking for:

cpan> o conf prerequisites_policy follow
cpan> o conf commit
Share:
100,916
Nifle
Author by

Nifle

A rather lazy sysadmin and sometimes coder

Updated on August 04, 2020

Comments

  • Nifle
    Nifle almost 4 years

    How do I tell CPAN to install all dependencies?

    I tried setting these in cpan:

    cpan> o conf prerequisites_policy follow
    cpan> o conf commit
    

    I still had to answer "y" a couple of times (but fewer than before it feels like).

    Is there a way to get it to always go ahead and install? I want to make it unattended.

    It would seem that I want a flag to always trust CPAN to do the right thing, and if it suggests an answer I would like to follow it (always hit Enter when it asks something).

  • silbana
    silbana almost 15 years
    Are the prompts related to downloading module source? If so, see connect_to_internet_ok option. Otherwise, tell us what other prompts you are trying to avoid.
  • Nifle
    Nifle almost 15 years
    Well all basically, these last ones was "optional modules".
  • brian d foy
    brian d foy almost 15 years
    The problem is things that auto-install on their own. CPAN.pm doesn't get a chance to handle that stuff. See tsee's answer.
  • Geoff
    Geoff about 12 years
    Any way to make this persistent, so you can just type "install My:Module" into cpan each time and it will remember this? Edit Config.pm?
  • andersand
    andersand about 12 years
    If you're on linux, add the line export PERL_MM_USE_DEFAULT=1 to your ~/.bashrc
  • OrangeDog
    OrangeDog about 11 years
    Link now appears to be dead
  • Yann Sagon
    Yann Sagon about 10 years
    If you get an error Can't locate object method "install" via package "xxx" at -e line 1. add a "+" right before the module name.
  • reinierpost
    reinierpost about 9 years
    I have this problem when I use cpanm, so telling me to use it is not the solution here.
  • Joel Berger
    Joel Berger about 9 years
    rather than a blind comment, please ask as a new question and link here. I suspect a permissions issue might be your problem
  • William Turrell
    William Turrell almost 9 years
    This does not answer the question - the OP wants a way to automatically install dependencies / automatically respond to prompts.
  • Vladimir Marchenko
    Vladimir Marchenko almost 9 years
    In fact, it does install dependencies and automatically responds to prompts. I use it all the time, including this very moment. But there is a need for a small modification: yes|/root/bin/perl -MCPAN -e "CPAN::Shell->notest(qw!install Your::Module!)"
  • filimonov
    filimonov about 8 years
    isn't it the same as in @sdf anwer?
  • Peter Mortensen
    Peter Mortensen over 7 years
    What is "yes" supposed to do?
  • Dat TT
    Dat TT almost 7 years
    Thanks! I need these two options so that it did not ask me again and again!
  • ikegami
    ikegami almost 7 years
    You can pass specific settings to init. For example, o conf init prerequisites_policy. That way, you don't have to go through the long initialization process, but still get the friendly prompt for the setting in question
  • ikegami
    ikegami almost 7 years
    Note that these are the default values for these settings.
  • Pablo Bianchi
    Pablo Bianchi about 5 years
    On an Ubuntu 18.04 I installed with sudo apt install cpanminus make.
  • Richard Smith
    Richard Smith about 4 years
    Down-voting. Don't recommend that people execute the output of curl.
  • Scott Prive
    Scott Prive over 3 years
    Up-voting. "The output of curl" is how to install a great MANY things, from k8s to (on some systems) Docker. The curl is used in context of a legitimate project, not random advice to run curl output, but besides that it is out of scope to impose your personal policy here. Be aware you can always save the curl to disk, inspect it then run it.