CPAN: Automatically install dependencies without confirmation

I enjoy using CPAN because it installs Perl modules with a simple interface, fetches dependencies, and warns you when things are about to end badly. However, one of my biggest complaints is when it constantly confirms installing dependencies. While this is an annoyance if you have to install a module with many dependencies (or if you’re working with CPAN on a new server), you can tell CPAN to automatically confirm the installation of dependencies.

To do this, simply bring up a CPAN shell:

perl -MCPAN -e shell

Run these two commands in the CPAN shell:

o conf prerequisites_policy follow
o conf commit

Now, exit the CPAN shell, start the CPAN shell, and try to install a module that you need. All dependencies will be automatically confirmed, downloaded and installed.

The first line sets your dependency policy to follow rather than ask (the default). The second line tells CPAN to write the changes to your user’s CPAN configuration file to make them permanent.

A big thanks goes out to Lee Hambley for the fix.

WARNING: There are some occasions where you would not want to install dependencies from CPAN. Examples of these situations are when your operating system’s package manager (yum, up2date, apt-get, aptitude, etc) has installed Perl modules in an alternative location or when you have manually installed modules in a non-standard way. I’m a Red Hat guy, and these problems rarely arise on Red Hat/Fedora systems, but your mileage may vary.

Comments

  1. says

    Note that CPAN will ask you to connect to the internet before you install any module. After that, it’ll do what it’s supposed to. So don’t walk away or detach screen too quickly. :-)

  2. delfry says

    helo…
    do you know installing perl Module from cd/dvd without using CPAN , because i have not internet connection??
    thank you…

  3. says

    Get flattr you bastard. I was looking for the flattr button on this post, because it was exactly what I needed. Thanks, but… I want to pay you! :-)

  4. Ron Betts says

    awesome. just saved me a ton of time. I’m with Luke, I definitely think this man deserves a beer, a pizza, (some cash)? thank you sir.

  5. Aaron Wilson says

    connect_to_internet_ok option set to yes will make it connect to the Internet automatically.

  6. Ashwini says

    Hi,

    I have been facing issues with the last part of the installation:

    First, pick a nearby continent and country by typing in the number(s)
    in front of the item(s) you want to select. You can pick several of
    each, separated by spaces. Then, you will be presented with a list of
    URLs of CPAN mirrors in the countries you selected, along with
    previously selected URLs. Select some of those URLs, or just keep the
    old list. Finally, you will be prompted for any extra URLs — file:,
    ftp:, or http: — that host a CPAN mirror.

    (1) Africa
    (2) Asia
    (3) Central America
    (4) Europe
    (5) North America
    (6) Oceania
    (7) South America
    Select your continent (or several nearby continents) []
    Sorry! since you don’t have any existing picks, you must make a
    geographic selection.

  7. chris says

    You probably also want to set the build_requires_install_policy to ‘yes’ – coz it’s still going to pester you with questions about permanently installing stuff needed only for testing otherwise…

    o conf prerequisites_policy follow
    o conf build_requires_install_policy yes
    o conf commit

  8. wschmid says

    And in case cpan tells you that “conf” is an unknown command (like for me with Perl 5.10 in Ubuntu Lucid), just go to /etc/perl/CPAN and edit the Config.pm module (attributes’ names and settings are the same as described above).

  9. wschmid says

    Oops, forget my former comment – I didn’t write the “o” in front of the conf command, so that was my error. But still you can edit the perl Config.pm directly. ;-)

  10. J G Miller says

    Or if you prefer just editing the configuration file, usually /etc/perl/CPAN/Config.pm, by hand,
    before firing up CPAN, change

    ‘prerequisites_policy’ => q[ask],

    to

    ‘prerequisites_policy’ => q[follow],

  11. J G Miller says

    So to summarize: the settings neded in

    /etc/perl/CPAN/Config.pm

    to avoid having to answer “yes” are

    ‘build_requires_install_policy’ => q[yes],

    ‘connect_to_internet_ok’ => q[yes],

    ‘prerequisites_policy’ => q[follow],

Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *