Debian

What is the Difference Between 'apt-get purge' and 'apt-get remove'

What is the Difference Between 'apt-get purge' and 'apt-get remove'
Installing and removing packages is a very common practice whenever you are working with any operating system of your choice. However, at times, you realize that you have installed some packages that you actually never needed or you have found a better alternative for them. In these situations, it is highly recommended to uninstall the irrelevant or unnecessary packages well in time so that they do not occupy any space on your system or create a hindrance in its performance.As far as the Linux operating system is concerned then it provides us with two different options to uninstall or remove a package i.e. 'apt-get purge' and 'apt-get remove'. In this article, our aim is to find out the main difference between the 'apt-get purge' and 'apt-get remove' commands. We will be doing this by theoretically stating this difference and then we will also show it to you by demonstrating an example. So, let us start our search for figuring out this difference.

Differentiating between 'apt-get purge' and 'apt-get remove':

Many people consider that 'apt-get purge' and 'apt-get remove' commands can be used interchangeably because after all, they serve the very same purpose i.e. both of them are responsible for uninstalling packages. This statement is partially true. It is absolutely right that both of these commands can be used to uninstall packages on the Linux operating system but the way they uninstall the packages is different.

The 'apt-get remove' command only uninstalls a package but its configuration file stays right there. However, when you remove a package with the 'apt-get purge' command, then a package along with its configuration file is deleted which means that no traces of that package are left behind in this situation.

At times, you are provided with the liberty of customizing a package according to the requirements of the task for which you have installed that package. For doing that, you have to make modifications in its configuration file. Now if you want to keep that personalized configuration file with you for future usage even after deleting a package, then you should make use of the 'apt-get remove' command but if you want the configuration file to be deleted along with the package, then you should use the 'apt-get purge' command. Now we will also walk you through an example so that you can easily verify the difference between these two commands.

Note: The scenario shown below has been demonstrated on Linux Mint 20. It can also be verified by running it on other Linux distributions.

Demonstrating the usage of 'apt-get remove' and 'apt-get purge' to highlight their difference:

For demonstrating the usage of 'apt-get remove' and 'apt-get purge', we are making use of the snapd package in Linux Mint 20. We will first try to remove that package with 'apt-get remove' and show you what happens after that. And then we will reinstall the same package and remove it with 'apt-get purge' and reveal what happens when you will do so. The point to be noted over here is that every package that you install on Linux has a configuration file with it which either resides in the Home folder or the etc folder. The configuration file of the snapd package is located within the etc folder and you can easily find it by searching for it as highlighted in the following image:

After verifying that the configuration file of the snapd package actually exists, you will have to proceed as follows:

Open the Linux Mint 20 terminal by clicking on its icon present on the taskbar and type the command shown below:

$ sudo apt-get remove snapd

Here, you can replace snapd with the name of any other package that you want to uninstall while making use of the 'apt-get remove' command.

As soon as you will execute this command by pressing the Enter key, you will be asked to provide your confirmation on uninstalling the specified package. Type “Y” to carry on with this process as you can also see from the image shown below:

The uninstallation process will take a few seconds to complete successfully and when it is done, you will be able to see the following output on your terminal:

Now go back to the etc folder and search for snapd. You will still be able to see its configuration file over there since the 'apt-get remove' command is not capable of removing the configuration files. This can be verified from the image shown below:

After doing this, we have reinstalled the very same snapd package for the sake of the demonstration. However, this time we will try to uninstall it while using the following command:

$ sudo apt-get purge snapd

Again, you can replace snapd with the name of any other package that you want to be uninstalled while using the 'apt-get purge' command.


When you will execute the 'apt-get purge' command by pressing the Enter key after typing it in your terminal, you will be prompted to confirm your action. You can simply do this by typing in “Y” and then press the Enter key as highlighted in the image shown below:

As soon as the uninstallation of the snapd package will complete, your Linux Mint 20 terminal will render the following output on it:

Now go back to the etc folder and try to search for snapd. This time, you will not be able to find any configuration file for this package since the 'apt-get purge' command removes all the traces of the package including its configuration file.

Hence, it is verified that the 'apt-get purge' command is capable of deleting the configuration files of the packages whereas the 'apt-get remove' command is not.

Conclusion:

In this way, you can easily make use of the 'apt-get purge' and 'apt-get remove' commands in different scenarios. You can delete any package of your choice by making use of these commands according to your needs. This article explains to you in detail the working of both these commands and it also explains the capabilities of both these commands. Another point to be noted over here is that even the 'apt-get purge' command can only delete those configuration files that are stored in the etc folder i.e. this command cannot delete the configuration files of the packages that are stored in the Home folder.

OpenTTD Tutorial
OpenTTD is one of the most popular business simulation games out there. In this game, you need to create a wonderful transportation business. However,...
SuperTuxKart for Linux
SuperTuxKart is a great title designed to bring you the Mario Kart experience free of charge on your Linux system. It is pretty challenging and fun to...
Battle for Wesnoth Tutorial
The Battle for Wesnoth is one of the most popular open source strategy games that you can play at this time. Not only has this game been in developmen...