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:
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:
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.
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.