65

I was doing a package removal with apt-get remove but then realized I should have done a --purge along with it to remove the configuration files.

Can I remove the packages configuration files easily or do I need to reinstall the package and then remove with a --purge?

5 Answers 5

70

Here is a simple command that will meet your request:

dpkg --purge $(dpkg --get-selections | grep deinstall | cut -f1)
2
  • @user1133275 I am very confused, are you complaining about the backticks? Nov 30, 2018 at 15:34
  • 12
    You should explain what exactly that command does. Somehow it removed mysql from a server I ran it on.
    – Sumit
    May 24, 2019 at 19:14
58

Yes you can.

From the command line:

sudo apt-get remove --purge packagename

This will remove all of the remaining files that the package installed.


You can also do this from a GUI:

  • Install Synaptic Install Synaptic from the Software Center
  • Run Synaptic
  • Find packages listed under "Not Installed (residual config)"
    Packages with residual configs
  • Right click the package and click, mark for complete removal Menu
  • Click the check button on the tool bar and click apply when the dialogue pops up. Dialogue
4
  • 7
    Under apt 1.0.9.2ubuntu2 apt-get remove --purge hasn't removed configuration files or databases if issued after the package was removed, indicating that Package xxxx is not installed, so not removed. dpkg --purge was needed for correct cleanup.
    – h7r
    Feb 18, 2015 at 19:09
  • My old php config files were not purged using this method.
    – Loenix
    May 14, 2021 at 7:19
  • @Loenix any files you've added to the folder or, any files within ~/.config will NOT be removed.
    – RolandiXor
    May 15, 2021 at 19:34
  • Similarly, in more recent Apt 2.6.1: sudo apt purge <pkg> did purge the residual config of a previously removed package. Feb 13 at 16:32
13

You can purge all previously uninstalled packages with aptitude:

aptitude purge ?config-files

You can also purge individual packages but then you would also have to purge the dependencies one by one. It is not practical.

1
  • My old php config files were not purged using this method.
    – Loenix
    May 14, 2021 at 7:18
3

Or on newer systems:

apt purge ?config-files
1

Purge do not remove configuration file atleast in my case it was not able to remove configuration file.

To remove configuration file:

  1. Get list of all configuration directory.
    cd ~/.config
    ls
  1. Remove the directories containing configuration for packagename
    rm -rf packagename
1
  • Finally, this was the only solution working to remove my old php configuration files...
    – Loenix
    May 14, 2021 at 7:19

You must log in to answer this question.

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