19

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.

32

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";
}
| improve this answer | |
17

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
| improve this answer | |
  • 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
  • 2
    "--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
  • 1
    --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. – Steven K7FAQ Mar 1 '18 at 16:58
  • 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 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.