How do I tell CPAN to install all dependencies?

PerlDependenciesCpan

Perl Problem Overview


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).

Perl Solutions


Solution 1 - Perl

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 2 - Perl

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 3 - Perl

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 4 - Perl

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 - Perl

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

cpan> o conf prerequisites_policy follow
cpan> o conf commit

Solution 6 - Perl

Set

prerequisites_policy

in the configuration.

See Config Variables.

Solution 7 - Perl

Maybe it's related to ExtUtils::AutoInstall or Module::AutoInstall being used. Try setting the PERL_AUTOINSTALL environment variable. (Cf. the documentation of those modules.)

Solution 8 - Perl

Personally I have only tried a couple of times to modify the settings in that way and have actually found it easier to drop into the CPAN.pm shell by giving cpan no arguments, then configuring CPAN.pm from the interactive prompt:

$ cpan
cpan> o conf init

This will initiate the CPAN.pm interfaces configuration utility. Simply run through it and specify "follow" where you need to (I forget the question offhand), and you should be good to go.

Solution 9 - Perl

I found this to be, by far, the quickest and most reliable way to install CPAN modules:

yes | perl -MCPAN -e "CPAN::Shell->notest(qw!install Your::Module!)"

Solution 10 - Perl

I'm writing this for benefit of people who may have come to this page searching for a way to install all module dependencies needed by a particular perl script. I wrote a script for that:

It should be run as ./installdep.pl yourscript.pl

#!/usr/bin/perl
`sudo apt install cpanminus`;
while (<>) {
	if (/USE /i)
	{
		my $line=$_;
		$line=~ s/\s//g;
		$line=~ /^(.*)\./;
		$line=~ s/\;//;
		$line=~s/^USE//i;
		$line=~s/lib.*//i;
		$line=~s/feature.*//i;
		$line=~s/strict//i;
		$line=~s/warnings//i;
		$line =~ s/^(.*)\(.*/$1/;
		unless ($line eq '') {
		my $cmd='sudo cpanm '.$line;
		print "Installing $line \n";
		open my $cmd_fh, "$cmd |";
		while (<$cmd_fh>) {
		  print "$_";
		}
		close $cmd_fh;
		print "\n";
	}
	}
}

This will use cpanminus to install all module dependencies required by your script. If cpanm isnt installed, it will install it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNifleView Question on Stackoverflow
Solution 1 - PerlkbosakView Answer on Stackoverflow
Solution 2 - PerlJoel BergerView Answer on Stackoverflow
Solution 3 - PerlAtentoView Answer on Stackoverflow
Solution 4 - PerlsdfView Answer on Stackoverflow
Solution 5 - PerlMark CView Answer on Stackoverflow
Solution 6 - PerlSinan ÜnürView Answer on Stackoverflow
Solution 7 - PerltseeView Answer on Stackoverflow
Solution 8 - PerlnumberwhunView Answer on Stackoverflow
Solution 9 - PerlVladimir MarchenkoView Answer on Stackoverflow
Solution 10 - PerlJoel G MathewView Answer on Stackoverflow