How do I tell CPAN to install all dependencies?
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
Comments
-
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 almost 15 yearsAre 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 almost 15 yearsWell all basically, these last ones was "optional modules".
-
brian d foy almost 15 yearsThe 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 about 12 yearsAny 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 about 12 yearsIf you're on linux, add the line
export PERL_MM_USE_DEFAULT=1
to your ~/.bashrc -
OrangeDog about 11 yearsLink now appears to be dead
-
Yann Sagon about 10 yearsIf 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 about 9 yearsI have this problem when I use
cpanm
, so telling me to use it is not the solution here. -
Joel Berger about 9 yearsrather than a blind comment, please ask as a new question and link here. I suspect a permissions issue might be your problem
-
William Turrell almost 9 yearsThis does not answer the question - the OP wants a way to automatically install dependencies / automatically respond to prompts.
-
Vladimir Marchenko almost 9 yearsIn 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 about 8 yearsisn't it the same as in @sdf anwer?
-
Peter Mortensen over 7 yearsWhat is "
yes
" supposed to do? -
Dat TT almost 7 yearsThanks! I need these two options so that it did not ask me again and again!
-
ikegami almost 7 yearsYou 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 almost 7 yearsNote that these are the default values for these settings.
-
Pablo Bianchi about 5 yearsOn an Ubuntu 18.04 I installed with
sudo apt install cpanminus make
. -
Richard Smith about 4 yearsDown-voting. Don't recommend that people execute the output of curl.
-
Scott Prive over 3 yearsUp-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.