I want to revert a file in /etc/ back to its originally-installed form. I have edited the file since it was installed. How can I revert this config file? Apt is smart enough not to overwrite edited config files, so how do I tell it that I want it to do so?

For argument's sake, let's say that I want to revert the file /etc/foo.conf from the package foo.

  • 2
    For all those who suggest purging and reinstalling foo, what if bar depends on foo and I don't want to remove bar? – Ryan C. Thompson Nov 12 '10 at 16:52

The answer provided by Ryan Thomson was heading to the right way. Still it would not be able to do the job (The details reason is given below).

The correct (and easiest) way of doing so is using -o with apt to pass dpkg option and force dpkg to ask you whether you want to retain the modified config files or the original ones. The command will be like this -

sudo apt-get --reinstall -o Dpkg::Options::="--force-confask" install foo

This would ask you a question like

Configuration file '/etc/foo/foo.conf'
 ==> Modified (by you or by a script) since installation.
     Version in package is the same as at last installation.
   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.
*** foo.conf (Y/I/N/O/D/Z) [default=N] ? 

You have to press either Y or I to install package maintainer's original config file. You can even press D to see what the changes or start a root shell with Z option to fix yourself.

Note: After the replacement, you'll find your modified file as at /etc/foo/foo.conf.dpkg-old

Why other options would not work?

Because the other options in dpkg doesn't work well. The options which deals with a package's config files are

  • --force-confmiss
  • --force-confnew
  • --force-confold
  • --force-confdef

--force-confmiss would not work when package version doesn't change. From man-page

If a conffile has been modified and the version in the package did change, always install the new version without prompting, unless the --force-confdef is also specified, in which case the default action is preferred.

--force-confmiss works with missing conffiles. It too will fail when version didn't change. Quoting man-page

confmiss: If a conffile is missing and the version in the package did change, always install the missing conffile without prompting. This is dangerous, since it means not preserving a change (removing) made to the file

--force-confold will retain modified version only if the version is changed. For same package, it too will fail. Quoting man-page

confold: If a conffile has been modified and the version in the package did change, always keep the old version without prompting, unless the --force-confdef is also specified, in which case the default action is preferred.

--force-confdef will also fail because the default action is to retain older file (Indicated from the message shown with --force-confask. It has line (Y/I/N/O/D/Z) [default=N] which means retaining is default. See above). And if --force-confnew is specified but version do not change, that too will not work. Quoting man-page

confdef: If a conffile has been modified and the version in the package did change, always choose the default action without prompting. If there is no default action it will stop to ask the user unless --force-confnew or --force-confold is also been given, in which case it will use that to decide the final action.

Only --force-confask will work, because it will explicitly ask you the question even when the version is same. Quoting man-page

confask: If a conffile has been modified always offer to replace it with the version in the package, even if the version in the package did not change (since dpkg 1.15.8). If any of --force-confmiss, --force-confnew, --force-confold, or --force-confdef is also given, it will be used to decide the final action.

Hope that will help.

  • Your answer was very comprehensive, thanks. Is it also possible to automatically answer the question with "y", i. e. effectively --force-confnew? I tried apt-get […] -y, but that didn't work. (If it is not possible, please also edit the answer to say so.) – Tim Landscheidt Dec 26 '16 at 11:42
  • @TimLandscheidt you're asking if it's possible to use --force-confnew without asking? I think that is the default case, which means it will retain your changes. --force-confask makes apt always ask the question, otherwise, you'd use other options if you already know the answer. – Anwar Dec 26 '16 at 12:54
  • 1
    Ha, I had tried -o Dpkg::Options::=--force-confnew unsuccessfully (as your answer predicted) and did not read the error message when I tried -o Dpkg::Options::="--force-confask --force-confnew". However, apt-get --reinstall -o Dpkg::Options::=--force-confask -o Dpkg::Options::=--force-confnew install $package correctly overwrote the change configuration files of $package. Thanks! – Tim Landscheidt Dec 26 '16 at 13:54

If the harm is already done, here's a command line way of getting back the official version of the configuration file. First, download the package file (either with apt-get --download-only as below, or from the package page on packages.ubuntu.com), then extract its contents in a temporary location. You can then copy the file into /etc. Make sure to respect the original permissions (most files in /etc are owned by root and mode 644 (i.e. word-readable and root-writable), but each exception is there for an important reason).

sudo apt-get --download-only --reinstall install foo
mkdir /tmp/foo
dpkg-deb -x /var/cache/apt/archives/foo_VERSION_ARCH.deb /tmp/foo

Note that this doesn't apply to the configuration files that are not from a package, such as /etc/fstab or /etc/passwd. If you lose these, you're on your own. (Most are very system-dependent anyway.)

For the future, I recommend using etckeeper Install etckeeper. Install the package and run sudo etckeeper init. This sets up version control for all files in /etc. You don't need to do anything else to manage etckeeper; you only need to interact with it when you want to do a version control operation, such as referring to older files. Files are automatically committed before and after each run of apt and every night (this is configurable).

By default, on Ubuntu, etckeeper uses Bazaar. Change the setting in /etc/etckeeper/etckeeper.conf before running etckeeper init if you prefer Darcs, Git or Mercury.

With Bazaar, to revert /etc/foo.conf to the last committed version:

cd /etc
sudo bzr revert foo.conf

If you want to go back further in time, use sudo bzr log foo.conf to view the history of the file, and sudo bzr revert -r 42 foo.conf if you've determined that revno: 42 is the revision you want to revert to.


You could download the package manually from packages.ubuntu.com, extract the file and replace your version with it.

Or you could:

sudo rm /etc/foo.conf # just for good measure
sudo apt-get --purge --reinstall install foo

The second feels a lot more brutish. It might wipe other config out too if it uses more than one file. The first is more clicking and effort but it seems much safer.

For the second, you might be able to just delete the file and --reinstall might replace it. If so, that would be safer.

  • 2
    No, deleting a configuration file is considered a valid modification, and is preserved by apt. – Ryan C. Thompson Nov 11 '10 at 18:00
  • Is it possible to purge and reinstall a package if other installed packages depend on it? – Ryan C. Thompson Aug 28 '12 at 0:11
  • @RyanThompson Yeah, apt-get --reinstall purge package won't hurt dependants. – Oli Aug 28 '12 at 7:00
  • Unfortunately it doesn't work. – Anwar Aug 28 '16 at 9:21

Depending on the package, you may find a default config file in /usr/share/doc/foo/examples.


Use Synaptic (Ubuntu tweak is even more convenient but synaptic is more straight forward) and choose "completely remove package". This will delete all config files (you might want to backup these files!).

Then reinstall. You're done.

With Ubuntu Tweak you get even more options for cleanup, rerolling and configuration backups. Maybe you want to give it a look. It's in the softwarecenter.

p.s.: Synaptic also uses the "purge" option (like mentioned by Oli above ...) - just with a GUI for more comfortable handling.

  • What package removes files in your home directory when you remove it? I would consider this a grave bug! – Gilles 'SO- stop being evil' Nov 11 '10 at 19:45
  • @Gilles: You're right. The personal settings within your home directory won't be touched by purge. I edited and corrected the above. sry – piedro Nov 12 '10 at 0:39
  • Purging the package may not be an option if others depend on it. – Ryan C. Thompson Aug 28 '12 at 0:11

I finally found the answer that I vaguely remembered from years ago:

dpkg --force-confnew --force-confmiss -i PACKAGE.deb

The "confnew" argument forces dpkg to replace modified config files with the package-provided ones, and the "confmiss" does likewise with config files that have been deleted.

According to this chatlog, you can also use these options through apt-get in the following manner:

apt-get -o DPkg::Options::="--force-confnew --force-confmiss" --reinstall install PACKAGE

which saves you from needing to find the deb file yourself.

Obviously, these options are dangerous and have the potential to blow away important system configuration files if misused.

  • The problem with --force-confnew is it will only install new config files if the version is change. If you're reinstalling same version, it will not install new config file as I have tested it explicitly – Anwar Aug 28 '16 at 8:11
  • And --force-confmiss will only install new config file if version is changed and config is missing. As described in the man page confmiss: If a conffile is missing and the version in the package did change, always install the missing conffile without prompting. This is dangerous, since it means not preserving a change (removing) made to the file. – Anwar Aug 28 '16 at 8:13

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.