Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

"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:

get_cpanm(){
    if [ \! -f /usr/local/bin/cpanm ]; then
            cd $TMP_DIR && curl --insecure -L http://cpanmin.us | perl - App::cpanminus
            if [ \! -f /usr/local/bin/cpanm ]; then
                    echo "Downloading from cpanmin.us failed, downloading from xrl.us"
                    curl -LO http://xrl.us/cpanm &&
            chmod +x cpanm &&
            mv cpanm /usr/local/bin/cpanm
            fi
    fi
    CPANM=$(which cpanm);
    if [ \! -f "$CPANM" ]; then
            echo "ERROR: Unable to find cpanm"
            return 1;
    fi
    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

 
discard

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.