Search code examples
perlcpan

Install Perl module with assume yes for given options non-interactively


Normally in linux Debian we do sth like this to install a package non-interactively e.g

sudo apt-get install -y Package_x_z

#[-y --assume-yes]

How we can do the same while installing a perl module e.g

sudo perl -MCPAN -e 'install DBI'

Solution

  • To prevent the CPAN client from asking whether to install prerequisites, start it in interactive mode

    perl -MCPAN -e shell
    

    and enter the commands:

    o conf build_requires_install_policy yes
    o conf prerequisites_policy follow
    o conf commit
    

    The commit command is optional, but it will update the default configuration, which I suspect is what you want. Without it, you may or may not (depending on whether autocommit is enabled in your CPAN config) need to make this change every time you want to do a prompt-less installation.

    These changes will deal with all of the CPAN client's routine questions about whether to install dependencies. For distributions which have questions embedded in their install scripts, you may also want to add

    o conf inactivity_timeout 60
    

    to set how long it will wait for a response before automatically going with the default answer to the question. (Set it to 0 to change it back to "wait forever".)