Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 rever the file /etc/foo.conf from the package foo.

share|improve this question
    
For all those who suggest purging and reinstalling foo, what if bar depends on foo and I don't want to remove bar? –  Ryan Thompson Nov 12 '10 at 16:52

5 Answers 5

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.

share|improve this answer

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.

share|improve this answer
1  
No, deleting a configuration file is considered a valid modification, and is preserved by apt. –  Ryan Thompson Nov 11 '10 at 18:00
    
Is it possible to purge and reinstall a package if other installed packages depend on it? –  Ryan 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

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

share|improve this answer

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.

share|improve this answer
    
What package removes files in your home directory when you remove it? I would consider this a grave bug! –  Gilles 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 Thompson Aug 28 '12 at 0:11
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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