20

I'm trying to make an update fully non interactive.(on ubuntu 14.04.3 LTS) I thought it will be easy with this type of command:

export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get upgrade -q -y --force-yes && apt-get dist-upgrade -q -y --force-yes

but no... I always have a question like:

Configuration file '/etc/cloud/cloud.cfg'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** cloud.cfg (Y/I/N/O/D/Z) [default=N] ?

So do you known how I can accept the default value automatically ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
David
  • 1,177
  • 3
  • 11
  • 26

2 Answers2

19

You need to pass some dpkg options to your commands, for instance:

export DEBIAN_FRONTEND=noninteractive
apt-get update && 
    apt-get -o Dpkg::Options::="--force-confold" upgrade -q -y --force-yes &&
    apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -q -y --force-yes

On a side note, I would recommend using only dist-upgrade, you will eventually end up with broken dependencies if you use upgrade.

RichVel
  • 7,030
  • 6
  • 32
  • 48
ryanpcmcquen
  • 6,285
  • 3
  • 24
  • 37
  • For any other fellow travelers that find this, the quoting around `Dpkg::Options` is wrong. it should be: `apt-get -o "Dpkg::Options::=--force-confold" dist-upgrade -y --force-yes` – Irving Jun 29 '17 at 20:27
  • 1
    For use within sudo, make sure to put the environment variable in front of the command rather than hoping sudo won't strip your envs, like: `sudo DEBIAN_FRONTEND=noninteractive apt-get -o "Dpkg::Options::=--force-confold" dist-upgrade -y --force-yes` – Irving Jun 29 '17 at 20:28
  • 1
    @Irving, that quoting worked for me, perhaps something changed recently? – ryanpcmcquen Jun 30 '17 at 15:51
  • `W: --force-yes is deprecated, use one of the options starting with --allow instead.` (apt v1.1 and newer). Looks like the new equivalent is `--allow-downgrades --allow-remove-essential --allow-change-held-packages` – jacobq May 21 '18 at 16:15
14

>= 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

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
  • 155,785
  • 88
  • 678
  • 743
  • 5
    I think you're missing the word "update" in your command someplace? – bovine Apr 02 '21 at 17:22
  • I still unfortunately get asked to select a drive when grub-efi is upgraded. Any ideas how to get it to select the first option by default? – Hackeron Dec 05 '22 at 13:52