48

Is there a way to do an apt-get dist-upgrade in Debian that not only automatically answers "yes" to all questions asked, but also uses reasonable defaults as answers to questions that are sophisticated enough to require various interactive dialog boxes to pop up? I'm thinking here of the keymap stuff that shows up when you upgrade libc6, and kernel image choices.

The goal is to be able to remotely initiate a rather large dist-upgrade - even for a machine that is severely behind the times - and not have to babysit it at all, unless something is just horribly, disastrously wrong.

Surely this is possible?

Thanks in advance!

Alex Balashov
  • 907
  • 2
  • 9
  • 16
  • For those that only want to upgrade (rather than dist-upgrade) on Ubuntu, try the [unattended-upgrade](http://packages.ubuntu.com/oneiric/unattended-upgrades) package. – Jo Liss Jul 08 '11 at 14:24

5 Answers5

48

If you set DEBIAN_FRONTEND=noninteractive (to stop debconf prompts from appearing) and add force-confold and force-confdef to your /etc/dpkg/dpkg.cfg file, you should have a completely noninteractive package installation experience. Any package that still prompts you for information has a release critical bug (and I say that as both an automation junkie and as a Debian developer).

womble
  • 95,029
  • 29
  • 173
  • 228
26

Florian Lohoff posted a way to get what womble suggested into a single command:

DEBIAN_FRONTEND=noninteractive \
apt-get \
-o Dpkg::Options::="--force-confnew" \
--force-yes \
-fuy \
dist-upgrade

Of course you might also use -o Dpkg::Options::="--force-confnew --force-confdef" (search the the dpkg man page for confnew). I'm not sure in what cases this would make a difference though. I personally need the non-interactive upgrade to bring vanilla images up-to-date, in which case I suppose always picking the new config file (without --force-confdef) is a reasonable thing.

Jo Liss
  • 2,818
  • 1
  • 22
  • 23
  • 1
    `W: --force-yes is deprecated, use one of the options starting with --allow instead.` – Alex Mar 12 '18 at 17:49
  • 1
    `--force-yes` can be replaced with `--allow-downgrades --allow-remove-essential --allow-change-held-packages` today for the same effect. – Mahn Feb 14 '20 at 15:44
5

Even though womble's answer above is generally good, it did not work for me and I had to do some additional research to go 100% unattended. I thought I'll share the result in a concise manner to make things simpler for future visitors.

The following is a script that will run according to the debian 8 release notes upgrade recommendations (mostly) along with flags and environment variables that will make it unattended. (the echos are just for debugging and could be removed - though I recommend keeping them so if the script gets stuck you will know where)

#!/bin/bash

apt-get remove apt-listchanges --assume-yes --force-yes &&

#using export is important since some of the commands in the script will fire in a subshell
export DEBIAN_FRONTEND=noninteractive &&
export APT_LISTCHANGES_FRONTEND=none &&

#lib6c was an issue for me as it ignored the DEBIAN_FRONTEND environment variable and fired a prompt anyway. This should fix it
echo 'libc6 libraries/restart-without-asking boolean true' | debconf-set-selections &&

echo "executing wheezy to jessie" &&
find /etc/apt -name "*.list" | xargs sed -i '/^deb/s/wheezy/jessie/g' &&

echo "executing autoremove" &&
apt-get -fuy --force-yes autoremove &&

echo "executing clean" &&
apt-get --force-yes clean &&

echo "executing update" &&
apt-get update &&

echo "executing upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy upgrade &&

echo "executing dist-upgrade" &&
apt-get --force-yes -o Dpkg::Options::="--force-confold" --force-yes -o Dpkg::Options::="--force-confdef" -fuy dist-upgrade
Tom Klino
  • 601
  • 1
  • 7
  • 14
  • 2
    Note: "--force-yes Force yes; this is a dangerous option that will cause apt to continue without prompting if it is doing something potentially harmful. It should not be used except in very special situations. Using force-yes can potentially destroy your system! Configuration Item: APT::Get::force-yes. This is deprecated and replaced by --allow-downgrades, --allow-remove-essential, --allow-change-held-packages in 1.1." – Alex Dec 03 '18 at 21:28
5

>= Apt 1.1

If you're using Apt 1.1 or above, --force-yes has been deprecated, so you've to use the options starting with --allow instead, e.g. --allow-downgrades, --allow-remove-essential, --allow-change-held-packages.

So the command is:

DEBIAN_FRONTEND=noninteractive \
  apt-get \
  -o Dpkg::Options::=--force-confold \
  -o Dpkg::Options::=--force-confdef \
  -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
  dist-upgrade

Note: Use --force-confold to keep old, and --force-confnew to keep new configs.

Source: CFE-2360: Make apt_get package module version aware.

Related:

kenorb
  • 5,943
  • 1
  • 44
  • 53
-3

From the apt-get(8) man page:

   -y, --yes, --assume-yes
       Automatic yes to prompts; assume "yes" as answer to all prompts
       run non-interactively. If an undesirable situation, such as
       changing a held package, trying to install a unauthenticated
       package or removing an essential package occurs then apt-get will
       abort. Configuration Item: APT::Get::Assume-Yes.

For reference, the -y option works on yum(8) as well.

koenigdmj
  • 1,055
  • 7
  • 12
  • 5
    I know about that. I use that flag and it successfully answers 'yes' to standard APT Y/N questions about keeping overwriting existing configs, etc., etc. Those aren't the questions I'm referring to. When I do an apt-get -y dist-upgrade it still gave me some 'dialog' prompts for what it considers big-ticket stuff, i.e. keymap changes, libc6-related service restart, etc. I was looking for an additional flag to turn that off as well. – Alex Balashov Aug 01 '09 at 02:29