23

I need to automatically install a package with its config file already present on the server.

I'm looking for something like:

apt-get install --yes --force-yes --keep-current-confs mysql-server

Probably a dumb question but I can't find such an option.

Falken
  • 1,702
  • 5
  • 18
  • 28

2 Answers2

41

Found the answer on Raphael Hertzog's Blog :

apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y mysql-server

It's dpkg's role to configure, therefore to chose which conf file to keep.

You can also add this to the config of the system by creating a file in /etc/apt/apt.conf.d/ with this content:

Dpkg::Options {
   "--force-confdef";
   "--force-confold";
}
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Falken
  • 1,702
  • 5
  • 18
  • 28
22

On current ubuntu systems you need a bit more:

export DEBIAN_FRONTEND=noninteractive ; apt-get dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
edlerd
  • 826
  • 8
  • 13
  • 1
    Silly question: why do you specify two seemingly mutually exclusive options at the same time? **confdef** vs **confold**? If this really works that's surely just a matter of the evaluation order? Not that I tried it ... – tink May 25 '16 at 19:56
  • 8
    "--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." – Craig Francis Aug 14 '17 at 11:58
  • 2
    `--force-yes` should be used as a last resort as it has the opportunity to break your system! [Please visit this mange page for details on using the --allow switches](https://manpages.debian.org/stretch/apt/apt-get.8.en.html). – Steven K7FAQ Mar 01 '18 at 16:58
  • 1
    The --allow-* flags were introduced in a version released after my initial reply :) Though people today should better use them in favor of the --force-yes flag. – edlerd Feb 24 '20 at 20:22
  • 1
    Seven years later, how do people view the use of "export DEBIAN_FRONTEND=noninteractive" these days? Good idea? Bad idea? – greymatter Apr 01 '21 at 18:21
  • Seems like all you really need is `DEBIAN_FRONTEND=noninteractive` – Brent Baccala Oct 19 '22 at 20:22