4

Is there a simple, backward-compatible way to install a Perl module silently using CPAN?

PERL_MM_USE_DEFAULT doesn't work for older versions that don't detect a default continent; CPAN will just loop at

Sorry! since you don't have any existing picks, you must make a geographic selection.

See CPAN::FirstTime.

It's possible to use a Perl snippet to load CPAN and configure it, but that's verbose and ugly.

Craig Ringer
  • 10,553
  • 9
  • 38
  • 59
  • I'm guessing you were trying to get CPAN.pm to work for automation which is challenging since it was aimed at interactive installs. – chicks Nov 18 '16 at 15:52
  • Correct. While using distro package management is often preferable, sometimes you're writing tooling that has to run on many different platforms, writing test harnesses, etc, and CPAN is the way to go. – Craig Ringer Nov 19 '16 at 01:08

3 Answers3

6

You should generally prefer to use distribution package mangement for Perl modules on Linux where possible, but sometimes the module you need isn't carried, you're using a different version of perl (maybe via perlbrew), etc. So you need to install with CPAN, and you probably need to automate it for use in Docker, Vagrant, AWS, etc.

There's a dedicated tool for this, cpanminus or cpanm. It can be installed directly without needing CPAN already set up, per the docs linked above.

Many distribution package management systems carry cpanminus too.

The wonderful perlbrew tool knows how to install cpanminus silently into its managed environment with

perlbrew install-cpanm

so you don't need to mess with PERL_MM_USE_DEFAULT, Perl scripts that use CPAN and configure it directly, expect scripts, manually creating files in ~/.cpan, etc.

Once cpanm is installed you can just

cpanm install IPC::Run

or whatever, and it runs with no fuss.

Craig Ringer
  • 10,553
  • 9
  • 38
  • 59
1

Please consider:

sudo cpan install YAML::XS <<<yes
aaaaa
  • 11
  • 1
0

Or alternatively:

sudo apt install cpanminus

cpanm -S YAML::XS

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
aaaaa
  • 11
  • 1