Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to install CPAN and some Perl modules automatically in a Scientific Linux (RHEL) installation script. Unfortunately the specific modules I want (at least one of them) cannot be found as RPM:s as far as I've seen.

So I need to install CPAN, configure it automatically (or with a config file) and then install the wanted modules (including dependencies) automatically as well.

This doesn't seem like a very unusual requirement, but I haven't seen any really good documentation on this. The problem is that whenever CPAN is launched for the first time an interactive configuration runs. Can this be skipped somehow? And how do I launch module installations directly from the command line?

share|improve this question

Try setting this environment variable before running CPAN:


It makes perl automatically answer "yes" when CPAN asks "Would you like to configure as much as possible automatically? [yes]"


share|improve this answer

"And how do I launch module installations directly from the command line?"

This should do:

perl -MCPAN -e 'install Your::Package'
share|improve this answer

If it's a repetitive task, it may pay to spend a few hours with cpan2rpm and turn them into RPM's. In my experience, CPAN runs (even interactive) are too plagued by unexpected events (version quirks, network problems, bogus tests failures) to be relied upon in a (semi-)automatic install.

share|improve this answer

This should do the magic:

    if [ \! -f /usr/local/bin/cpanm ]; then
            cd $TMP_DIR && curl --insecure -L | perl - App::cpanminus
            if [ \! -f /usr/local/bin/cpanm ]; then
                    echo "Downloading from failed, downloading from"
                    curl -LO &&
            chmod +x cpanm &&
            mv cpanm /usr/local/bin/cpanm
    CPANM=$(which cpanm);
    if [ \! -f "$CPANM" ]; then
            echo "ERROR: Unable to find cpanm"
            return 1;
    return 0
cpanm Time::HiRes CGI Moose Config::JSON other::cpanmodules
share|improve this answer

You might want to look at cpanm for this; it's lightweight, shell scriptable, and much simpler than classic CPAN.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.