Wednesday, June 5, 2013

Restore missing conf files of a package in /etc

Here is my case:

- Remove nginx by using the command: sudo apt-get remove nginx

- Delete /etc/nginx config folder: sudo rm -r /etc/nginx

- Re-install nginx: sudo apt-get install nginx

- Cannot start nginx because of missing conf file! Oops!

After awhile searching on the Internet, I found a solution:

All you need to do:
  • Find the list of conffiles provided by the package:
    dpkg --status <package>
    (look under the Conffiles: section).
  • Remove those conffiles yourself.
  • Reinstall the package. If you've found the .deb file,
    dpkg -i --force-confmiss <package_deb>.deb
    Alternatively, passing the dpkg option via apt should work:
    apt-get install --reinstall -o Dpkg::Options::="--force-confmiss" <package>

Especially in Ubuntu, I have to look for the packages in the cache folder, and It works:

sudo dpkg -i --force-confmiss /var/cache/apt/archives/nginx*.deb