25

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.

2 Answers 2

43

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";
}
23

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
7
  • 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, 2016 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." Aug 14, 2017 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. Mar 1, 2018 at 16:58
  • 2
    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, 2020 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 1, 2021 at 18:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .