zerohero has asked for the wisdom of the Perl Monks concerning the following question:

I would like a more trouble-free (automatic) installation from CPAN. Typically, I use CPAN interactively, yet just hit ENTER for all the defaults, without even looking. Is there a way to invoke cpan from the command-line to automatically (and silently) install modules. I find the standard interactive CPAN to be really overkill for most purposes. I see there have been other efforts like cpanp and cpanmm which seem to be aimed (at least partially) in this direction.

Replies are listed 'Best First'.
Re: Automated installation from CPAN
by tod222 (Pilgrim) on Nov 20, 2010 at 22:32 UTC

    Since seeing it mentioned in Chromatic's blog about What's Going Right in Perl I've been happily using cpanminus.

    It's much easier to use than CPAN.pm and CPANPLUS.

    You can optionally use local::lib first to set up a private lib for modules:
    # set up a local perl module location inside a directory (csh variant) perl -Mlocal::lib=./ >.setenv.csh source .setenv.csh # once a local perl location is set up, install cpanminus curl -L http://cpanmin.us | perl - App::cpanminus
Re: Automated installation from CPAN
by Corion (Patriarch) on Nov 20, 2010 at 21:29 UTC

    Depending on what prompts you mean, configuring it to follow prerequisites automatically could do it:

    cpan cpan> o conf prerequisites_policy follow cpan> quit

    Alternatively, take a look at App::cpanminus.

Re: Automated installation from CPAN
by JavaFan (Canon) on Nov 20, 2010 at 21:22 UTC
    cpan -i Module usually does it for me. Haven't had the need to play with cpanminus yet.
Re: Automated installation from CPAN
by Khen1950fx (Canon) on Nov 20, 2010 at 23:30 UTC
    There is a way to silently install modules: From the CPAN shell
    o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
    or
    o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"
    Then
    o conf commit
Re: Automated installation from CPAN
by YordanGeorgiev (Acolyte) on Sep 16, 2017 at 13:26 UTC
    use strict; use warnings; use 5.10.0; use ExtUtils::Installed; # quick and dirty check for prerequisites perl modules: # courtesy of:http://stackoverflow.com/a/9340304/65706 # if you have a calling bash script call by : # perl "/path/to/isg_pub_preq_checker.pl" # export ret=$? # test $ret -ne 0 && doExit 1 "[FATAL] perl modules not found!!!" my $PrintOkCheck = 1; doCheckUbuntuOSPackages(); # check that all the required modules are installed my ($ret, $msg) = doCheckRequiredModules(); unless ($ret == 0) { print "$msg"; # give some time for the user to react print "printing all installed modules :"; my $c = 9; for (my $i = 0; $i <= $c; $i++) { print(($c - $i) . '.'); sleep 1; } print "\n"; doListAllInstalledModules(); print "\n"; } exit(0); sub doListAllInstalledModules { my $instmod = ExtUtils::Installed->new(); foreach my $module ($instmod->modules()) { my $version = $instmod->version($module) || "???"; print "found module:$module -- v$version\n"; } } #eof sub sub doCheckUbuntuOSPackages { my @ospackages = qw( libxml-atom-perl postgresql-9.6 libdbd-pgsql curl libwww-curl-perl ); my $cmd = 'sudo apt-get update' ; print `$cmd` ; for (@ospackages) { my $cmd="sudo apt-get install -y $_ \n" ; print `$cmd` ; } } sub doCheckRequiredModules { my @modules = qw( ExtUtils::Installed Carp::Always Data::Printer File::Copy File::Find File::Path Excel::Writer::XLSX Spreadsheet::ParseExcel Spreadsheet::XLSX Spreadsheet::ParseExcel::FmtJapan Net::Google::Spreadsheets::V4 Net::Google::DataAPI::Auth::OAuth2 Term::Prompt Net::Google::Spreadsheets; Text::CSV_XS WWW::Curl::Easy ); for (@modules) { eval "use $_"; if ($@) { #flush the screen print "\033[2J"; print "\033[0;0H"; my $msg = "\n\n\n [FATAL] did not found the following prerequisite per +l module: $_ \n\n"; $msg .= "\n # ::: START copy paste ::: "; $msg .= "\n#you must install it otherwise the application will n +ot work"; $msg .= "\n#the module could be installef by running the following +commands:"; # if the user knows already the difference between the running t +he cmd # with sudo or he / she probably knows already how-to install pe +rl modules $msg .= "\n# as a start cnfigure the cpan to install dependancies f +irst \n"; $msg .= "\n" . 'perl -MCPAN -e \'my $c = "CPAN::HandleConfig"; $c->load(doi +t => 1, autocnfig => 1); $c->edit(prerequisites_policy => "follow"); +$c->edit(build_requires_install_policy => "yes"); $c->commit\'' . "\n"; $msg .= "\n#than install the $_ module by running: \n"; $msg .= "\nPERL_MM_USE_DEFAULT=1 sudo perl -MCPAN -e 'install $_ +'\n\n\n"; $msg .= "\n # ::: STOP copy paste ::: \n\n\n"; $msg .= "\n# if you seem to be stuck in circular reference kind of +loop try even :\n"; $msg .= "\n # ::: START copy paste ::: "; $msg .= "\nsudo PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'CPAN::Shel +l->force(qw( install $_));'\n"; $msg .= "\n # ::: STOP copy paste ::: "; $msg .= "\n# You may end-up now with Ctrl + C \n\n\n"; return (1, "$msg") if $@; } else { say "[INFO ] ::: ok ::: check for prerequisite perl module : $_" if $PrintOkCheck == 1; } } #eof foreach module return (0, "all required modules found"); }
Re: Automated installation from CPAN
by melezhik (Monk) on Sep 28, 2017 at 17:31 UTC
    Hi! You can use Sparrowdo cpan-package , it uses cpanminus under the hood, handles various cases ( install into a prefix and for different users ), as well as installing CPAN modules remotely over ssh.