95

When running apt-get -y install <packages ...> on Ubuntu 10.04 I would like apt-get (or aptitude if that makes it easier) to not prompt me when installing additional dependencies (behavior of -y as I understand it) and but not prompt me about overwriting configuration files, instead assume to keep the existing ones always (which is usually the default). Unfortunately --trivial-only seems to be the inverse of -y and not affect the prompt that is shown, according to the man page.

In particular packages auch as samba, nullmailer, localepurge and lighttpd have forced me to interact with the terminal, even though the whole procedure was scripted and meant to be non-interactive.

muru
  • 197,895
  • 55
  • 485
  • 740
0xC0000022L
  • 5,720

1 Answers1

126

You may use:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

For only specific packages, e.g. mypackage1 mypackage2:

sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install mypackage1 mypackage2

Source: http://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/

Avoiding the conffile prompt

Every time that dpkg must install a new conffile that you have modified
(and a removed file is only a particular case of a modified file in dpkg’s eyes),
it will stop the upgrade and wait your answer. This can be particularly annoying for
major upgrades. That’s why you can give predefined answers to dpkg with the help
of multiple --force-conf* options:

    --force-confold: do not modify the current configuration file, the new version
is installed with a .dpkg-dist suffix. With this option alone, even configuration
files that you have not modified are left untouched. You need to combine it with
--force-confdef to let dpkg overwrite configuration files that you have not modified.
    --force-confnew: always install the new version of the configuration file, the
current version is kept in a file with the .dpkg-old suffix.
    --force-confdef: ask dpkg to decide alone when it can and prompt otherwise. This
is the default behavior of dpkg and this option is mainly useful in combination with
--force-confold.
    --force-confmiss: ask dpkg to install the configuration file if it’s currently
missing (for example because you have removed the file by mistake).

If you use Apt, you can pass options to dpkg with a command-line like this:

$ apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade

You can also make those options permanent by creating /etc/apt/apt.conf.d/local:

Dpkg::Options {
   "--force-confdef";
   "--force-confold";
}

You can find more information and more options in the dpkg manual at http://manpages.ubuntu.com/manpages/xenial/en/man1/dpkg.1.html or man dpkg and i.e. look for "confdef".

  • 39
    "I believe this is self-explanatory" ... proceeds to use options I've never seen anyone use for apt-get – notbad.jpeg Jun 10 '15 at 13:42
  • 2
    @notbad.jpeg: I believe the remark was aimed at the naming of those options. I find the names indeed self-explanatory. Of course knowing to use them wasn't :-D – 0xC0000022L Nov 16 '15 at 08:46
  • I'd think they're mutually exclusive (force default vs force old), and don't understand why you'd specify both ... – tink May 25 '16 at 19:53
  • @tink, no --force-confold and --force-confnew are mutually exclusive. In some cases (I'm not too sure when, though) there may not be a clear default action to be taken so --force-confdef would not know what to do. In such cases, the --force-confold is chosen. The default, though, can be to install the new configuration file which I know a server has done in the past because some options were wrong (unsecure) so instead of letting you use the wrong information, by default they overwrote your file... (they made a backup first though.) – Alexis Wilke Jul 20 '16 at 05:27
  • 4
    what about -y ? – JDS Jan 09 '17 at 20:58
  • 4
    See also: https://linux.die.net/man/1/dpkg under the --force section, it describes the confold and confdef options. Also helpful: apt-config dump from https://askubuntu.com/questions/254129/how-to-display-all-apt-get-dpkgoptions-and-there-current-values – thom_nic Oct 16 '17 at 14:55
  • 3
    "self-explanatory"... hmm, I found that description extremely confusing, especially whether to use them in combination or not. The one that cleared things up was dpkg(1). Thanks @thom_nic. – Lloeki Nov 13 '17 at 10:21
  • Answer updated as per the comments :) – Savvas Radevic Jan 23 '18 at 13:58
  • The seems to be contradictions between http://raphaelhertzog.com/2010/09/21/debian-conffile-configuration-file-managed-by-dpkg/ and http://manpages.ubuntu.com/manpages/xenial/en/man1/dpkg.1.html about the behavior or using confdef and confold together. At the very least, the docs are confusing, and I think it best that someone clarify by editing this answer. – Johnny Utahh Dec 14 '20 at 17:56
  • 1
    For now, can someone confirm that I'm interpreting the following point correctly? When confold and confdef are used concurrently, it means: "overwrite conf files that have not changed (if the upgraded pkg has a new one), and keep the ones that have (changed)." – Johnny Utahh Dec 15 '20 at 00:13