The process for removing packages using apt-get on Ubuntu is simple, but a little unclear since there are multiple commands that can be used depending on your goals. There are two main questions you need to ask yourself before deciding which command to use:
- Do I want remove the package AND associated config files / data?
- Do I want to remove any dependent packages that are no longer needed?
All of the commands below will remove the specified package. The differences center around whether or not you want to keep associated config files / data and dependent packages that were installed as a result of installing the primary package.
Let’s take a quick look at all of our options and then we’ll discuss how to combine them into the exact command we want.
- remove (package name) - The remove command will remove the package, but it will leave configuration files and data in place.
- autoremove (package name) - The autoremove command takes the remove command a step further. It will remove the package AND any associated dependencies that are no longer needed.
- purge (package name) - The purge command takes the remove command a step further as well. It will remove the package AND any associated config files / data that were installed in system directories. It will not change dependent packages though.
- - -purge - The - -purge option can be attached to any of the commands above. It gives any of the commands the same capability as the purge command.
- - - auto-remove - The - -auto-remove option can be attached to any of the above commands. It gives any of the the same capability as the autoremove command.
A note about removing config files and data
None of the removal options will remove config files or data that have been placed in the user’s home directory. The package manager is unable to understand if these files are still in use (even though they might have been generated during the install) and they are left alone. You will have to find and delete these files manually if necessary.
Here are a couple different removal options presented in order from least complete to most complete:
1 2 3 4
sudo apt-get remove (package_name) # Removes only the package. Leaves config files and dependent packages untouched sudo apt-get purge (package_name) # Removes the package and data. Leaves dependent packages untouched sudo apt-get autoremove (package_name) # Removes packages and unneeded dependent packages, but leaves all data. sudo apt-get autoremove - -purge (package_name) # Removes package, unneeded dependent packages and all data.
While reading tutorials on the internet, you will probably run into various forms of the remove and purge commands. Hopefully, you’re beginning to get the sense that some of these commands are equivalent. If you take a look at the apt-get man page via man apt-get it confirms that some of these commands are equivalent. Here a quote from the - - purge option description in the man page:
Use purge instead of remove for anything that would be removed. An asterisk (“*”) will be displayed next to packages which are scheduled to be purged. remove –purge is equivalent to the purge command. Configuration Item: APT::Get::Purge.
As a result, the following commands are completely equal:
|apt-get remove - -purge||apt-get purge|
|apt-get auto-remove - -purge||apt-get purge - - auto-remove|
|apt-get remove - -auto-remove||apt-get autoremove|
|apt-get remove - -auto-remove - - purge||apt-get purge - -auto-remove|
We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!