Home Linux Commands What is the Difference Between ‘apt remove’ and ‘apt purge’?

What is the Difference Between ‘apt remove’ and ‘apt purge’?

Brief: This article theoretically and practically looks at the different usage of apt remove and apt purge commands.

The apt package manager is a command-line utility used by Debian-based Linux distributions to install, update, upgrade, remove, and purge associated package(s). In this case, we will be using it to uninstall an existing application.

apt remove vs apt purge Commands

When addressing apt remove vs apt purge commands, there is always some confusion in their applicability. Both commands reside within Debian-based Linux distributions like Ubuntu. Also, both commands seem to perform similar functionality.

For instance, when uninstalling an application using the apt remove command, adhere to the syntax:

$ sudo apt remove package_name

On the other hand, uninstalling an application using the apt purge command adheres to the syntax:

$ sudo purge remove package_name 

Therefore, what is the need of using two similar commands to uninstall a Debian-based Linux package?

Differentiating apt remove vs apt purge Commands

At face value, both of these commands are useful in uninstalling a Linux package. However, the apt purge command goes the extra mile to remove any configuration files associated with the Linux package. The use of both commands does not interfere with the targeted application’s files residing in the $HOME directory.

$ ls -l $HOME
List Home Directory Content
List Home Directory Content

The $HOME directory points to the current system user’s default files and directories. It is associated with an absolute path e.g. /home/ubuntu.

Using apt remove to Uninstall a Package

Consider the existence of an already-installed Linux application like mplayer and the files associated with this package can be traced via the following find command:

$ sudo find / -type d -name *mplayer 2>/dev/null 
Find Installed Package Files
Find Installed Package Files

The find command starts its search from the root (/) to search for all directories (-type d) named mplayer (-name *mplayer). To discard any errors associated with the find operation, we use 2>/dev/null where 2 detects the standard error and redirects it via > to the /dev/null virtual device. Virtual devices emulate the working of real devices in Linux.

If we were to remove the mplayer application using apt remove, we will implement the following command:

$ sudo apt remove mplayer
Remove Package Using apt remove Command
Remove Package Using apt remove Command

Now that we have successfully uninstalled the mplayer application, let’s check what files remained in the system. We will use the following find command to look for a directory with the name mplayer.

$ sudo find / -type d -name *mplayer 2>/dev/null 
Find Files of Uninstalled Package
Find Files of Uninstalled Package

As per the above screen capture, the user home (/home/ubuntu/.mplayer) directory and the, etc (/etc/mplayer) directory still have data belonging to the mplayer app.

Using apt purge to Uninstall a Package

The mplayer app files before their uninstallation can be retrieved with the following find command.

$ sudo find / -type d -name *mplayer 2>/dev/null 
Find Installed Package Files
Find Installed Package Files

To uninstall the mplayer app using apt purge, we will implement the following command:

$ sudo apt purge mplayer 
Remove Package Using apt purge Command
Remove Package Using apt purge Command

The apt purge command will uninstall a package along with all the dependencies and configuration files associated with the package.

Now use the following find command to trace any mplayer app-related file directories within the Linux system.

$ sudo find / -type d -name *mplayer 2>/dev/null 
Find Files of Uninstalled Package
Find Files of the Uninstalled Package

As per the above screen capture, user home (/home/ubuntu/.mplayer) is the only directory with data belonging to the mplayer app.

Both apt remove and apt purge commands will successfully uninstall an app from a Debian-based Linux distribution. However, apt purge goes the extra mile to remove the app configuration files (if any) in the /etc directory.

Therefore, what is the recommended usage of the apt purge command? Use it when there is a need to remove custom configuration files and leftover dependencies associated with the targeted app.

On the other hand, apt remove only uninstalls an app and leaves its custom configuration files. Therefore, if apt remove does the bare minimum, prioritize it as a default option since multiple apps tend to share dependencies.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.