The difference between apt remove, purge, and autoremove

Lynn
3 min readMay 5, 2022

--

A brief discription to help you understand the main difference between ench apt commands related to package uninstallation.

Photo by Ryland Dean on Unsplash

apt remove

remove is identical to install except that packages are removed instead of installed.

It will remove the binaries, but leave configuration files, data files, and dependencies installed with it on installation time un touched.

apt purge

purge is identical to remove except that packages are removed and purged (any configuration files are deleted too).

It will remove about everything regarding the package, but not the dependencies installed with it on installation, which is particularly useful when you want to “start all over” with an application because you messed up the configuration.

However, purge won’t touch configuration or data files inside the user’s home folder (e.g. /home/User/hiddenFolders). There is no easy way to get those removed as well.

Note that other tools like aptitude will only remember dependency information for packages that it has installed.

apt autoremove

autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

In other words, it will only goes through the catalog and remove any left over packages that were not directly installed and that are not required by packages that are installed. Say that you install apache, it will install a lot of libraries. If you remove apache, all these libraries will be left behind until you run autoremove.

The only thing you should watch for, is if you started using one of the dependencies say “Python” but never actually installed it yourself; then it will be removed.

apt clean

clean clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archieves/partial/.

apt autoclean

Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it going out of control.

Extra

Do not remove files belonging to packages without using the package manager! It will get confused and is the wrong way to do things.

If you don’t know to which package a file belongs, try this:

dpkg -S /path/to/file

For some applications compiled from their source codes, the best way is to refer to its README, and remove it manually.

Appendix: dpkg

dpkg is a tool to install, build, remove and manage Debian packages, and maintains some usable information about available packages.

But it’s olnly useful to the system directories, not Home directories.

Two common examples are as follows:

dpkg -s <package name>

-s is the same as — status,which reports status of specified package.

dpkg -S <Path/ to/ file>

-S is the same as — search, which searches for a filename from installed packages. (i.e. list where files were installed) (similar to which)

And `-l` can list all installed packages, along with package version and short description, while `-L` can list files installed to your system from package-name.

just run

dpkg -l 'cmake*'

to list packages related to cmake in `/var/lib/dpkg/status`

Use file `/var/lib/dpkg/available` to find out all package names available to you

--

--