Understanding the Differences Between apt-get remove and apt-get purge

Wed Jan 04 2023

apt-get purge

  • Completely removes a package and its configuration files.
  • Also removes any packages that depend on the package being purged.
  • Can be used to free up disk space.

apt-get remove

  • Removes a package but leaves its configuration files intact.
  • Does not remove any packages that depend on the package being removed.
  • Can be used to downgrade a package to a previous version.

Comparison

Feature apt-get purge apt-get remove
Removes package Yes Yes
Removes configuration files Yes No
Removes dependent packages Yes No
Can be used to free up disk space Yes No
Can be used to downgrade a package No Yes

Example

To purge the apache2 package, you would use the following command:

|
sudo apt-get purge apache2

To remove the apache2 package, but leave its configuration files intact, you would use the following command:

|
sudo apt-get remove apache2

Additional notes

  • apt-get purge is a more destructive command than apt-get remove. It should be used with caution.
  • If you are not sure whether you should use apt-get purge or apt-get remove, it is best to use apt-get remove.
  • You can also use the apt-get autoremove command to automatically remove any packages that are no longer needed.