How do I automate CPAN configuration?

The first time you run cpan from the command line, you are prompted for answers to various questions. How do you automate cpan and install modules non-interactively from the beginning?


Since it hasn't been mentioned yet, cpanminus is a zero-conf cpan installer. And you can download a self-contained executable if it isn't available for your version control.

The cpanm executable is easily installed (as documented in the executable itself) with:

curl -L http://cpanmin.us | perl - --self-upgrade
# or
wget -O - http://cpanmin.us | perl - --self-upgrade

I was looking for an easy solution for this as well and found that this works:

(echo y;echo o conf prerequisites_policy follow;echo o conf commit)|cpan

Just thought I would post it here in case anyone else comes along.


Make your own CPAN.pm config file. The recent versions of the cpan command have a -J switch to dump the current config and a -j switch to load whatever config you like.


Recent versions of CPAN.pm ask as first question whether the rest of the configuration should be run automatically, so it is advisable to upgrade CPAN.pm (manually) first: tarballs, repo.