198

I have a server build script which uses apt-get to install packages. It then puts pre-written configuration files directly in place, so the interactive post-install configuration dialog in packages such as postfix is not needed. How do I skip this stage of the installation? It creates a piece of manual intervention that I would rather avoid.

I am aware of the -qq option, but the manpage warns against using it without specifying a no-action modifier. I do want to perform an action, I just want to suppress a specific part of it.

Wolph
  • 865
  • 1
  • 7
  • 12
jl6
  • 2,575
  • 2
  • 18
  • 19

3 Answers3

305

You can do a couple of things for avoiding this. Setting the DEBIAN_FRONTEND variable to noninteractive and using -y flag. For example:

export DEBIAN_FRONTEND=noninteractive
apt-get -yq install [packagename]

If you need to install it via sudo, use:

sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install [packagename]
Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
lynxman
  • 9,397
  • 3
  • 25
  • 28
  • 39
    This worked for me until one day it didn't. Some kind of "urgency=high" message. You need `DEBIAN_FRONTEND`, `y` AND the `q` flag set, i.e. `DEBIAN_FRONTEND=noninteractive apt-get -yq install [packagename]` – Jeff Mixon Jul 20 '16 at 06:45
  • Did no work for me when installing iptables-persistent :/ – user1133275 Oct 16 '20 at 19:11
2

I've found that setting -yqq and DEBIAN_FRONTEND=noninteractive don't work in some cases where apt-get stalls at the end with

Restarting the system to load the new kernel will not be handled automatically, so you should consider
rebooting. [Return]

It will not exit until after you press the enter key.

My solution to this is to do everything everyone else suggested, but also with yes piped to apt-get as follows

yes | sudo DEBIAN_FRONTEND=noninteractive apt-get -yqq purge 'my-package'
Michael Altfield
  • 739
  • 2
  • 8
  • 23
0

You can redefine apt as a function in your bash scripts if you are going to be running these commands regularly in automated stacks, so that you don't have to remember everything:

## apt ##
function apt {
    export DEBIAN_FRONTEND=noninteractive
    export DEBIAN_PRIORITY=critical
    export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
    command /usr/bin/apt --yes --quiet --option Dpkg::Options::=--force-confold --option Dpkg::Options::=--force-confdef "$@"
}

Or better yet just rename it to like my_apt or whatever.

And then it can be used in child functions, here are some examples we use in SlickStack:

## ss_apt_update ##
function ss_apt_update {
    apt update > /dev/null 2>&1
}

## ss_apt_upgrade ##
function ss_apt_upgrade {
    apt upgrade > /dev/null 2>&1
}

## ss_apt_full_upgrade ##
function ss_apt_full_upgrade {
    apt full-upgrade > /dev/null 2>&1
}
Jesse Nickles
  • 264
  • 2
  • 14