46

I'm new to Linux/Ubuntu - and I'm wondering if the behaviour I'm seeing is as designed. I have installed vsftpd:

 sudo apt-get install vsftpd

Then I remove:

 sudo apt-get remove vsftpd

However, looking in /etc I can see that vsftpd.conf is still present. Can someone explain why this is happening (I am assuming the remove would remove all files relating to vsftpd) ?

2
  • I thought you had to purge it
    – Dr_Bunsen
    Jun 6, 2012 at 14:19
  • 1
    Ah! So that's how you remove something without removing config files! That's what I want to do...just in case I decide to reinstall later. Jan 8, 2018 at 17:53

3 Answers 3

60

Use sudo apt-get purge <program> instead, to remove config files as well.

29

You're looking for purge:

sudo apt-get purge vsftpd

will also delete the config files. You can do this even after you've already removed the package.

4
  • 2
    I believe there is even some option of dpkg to list all the packages that were once installed but removed...? Ah yes, see here: ascending.wordpress.com/2007/04/10/…
    – codeling
    Jun 6, 2012 at 14:03
  • 2
    Does sudo apt-get remove --purge <program> have the same effect? Dec 26, 2012 at 21:47
  • 2
    @asymptotically Yes. Quoting the apt-get man page: "remove --purge is equivalent to the purge command". If you want to know everything about the apt-get command, run man apt-get.
    – JW.
    Dec 28, 2012 at 16:26
  • I did notice that a file /etc/vsftpd.conf.save is created and remains after the purge. This should be the accepted answer. Dec 13, 2016 at 15:40
3

Still see some older configs here and there? Here's The Answer :)

sudo apt-get clean && sudo apt-get autoremove --purge -y $(dpkg --list |
grep '^rc' | awk '{print $2}')

All the suggested "apt purge" commands did leave some residue in places like:

  • /boot
  • /lib/modules
  • some headers, etc.

Ideally, you should never handle those 'leftovers' manually. Instead, to effectively remove purged kernel configuration files in Ubuntu, run the above command. This command will identify removed packages with lingering configurations and thoroughly flush them out!

In general it's a good practice to run the above cleanup command periodically to maintain system cleanliness.


TL;DR Very long explanation:

"apt-get clean" command removes cached package files from the local package cache, freeing up disk space by deleting downloaded .deb files that are no longer needed.

"dpkg --list" command shows information about both installed and removed packages. The status column in the output indicates the status of each package. The status codes (1st 2-3 letters on each output line) include: - ii: Package is installed. - rc: Package is removed but its configuration files are still present.

So, if you see a package with the status rc, it means the package has been removed, but its configuration files remain on the system.

"grep" command will only select lines that start with letters "rc" by using regular expression '^rc'.

Then we pipe output to awk command. The 'awk' is a versatile and powerful programming language and command-line utility in Unix-like systems, designed for text processing, pattern scanning, and data extraction. We tell it to split each line by using spaces as delimiter and print 2nd "column" only: '{print $2}' - this will print the name of the package.

In Bash, the $( ) syntax is used for command substitution. It allows you to replace a command within a command with its output. Now we have a list of undesired packages that we want to purge from the system.

Next "sudo apt-get autoremove --purge -y" command will take the list of packages to remove and:

  • sudo: Executes the command with administrative privileges.
  • apt-get: The package management command used to interact with the Advanced Package Tool (APT).
  • autoremove: Removes packages that were automatically installed as dependencies for other packages but are no longer required.
  • purge: Removes the package and its configuration files. This ensures a complete removal.
  • -y: Assumes "yes" as the answer to all prompts, making the process non-interactive and automated.

    So, this command essentially removes unnecessary packages and their configuration files, freeing up disk space and ensuring a clean system by removing residual dependencies.

Happy days!

You must log in to answer this question.

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