On Ubuntu, apt remove, apt purge, and apt autoremove all uninstall a package, but they stop at different layers of it. The difference decides what survives: the package files, the configuration, or the leftover dependencies.
I installed a small text-drawing filter called boxes and removed it three separate ways to record what each command clears, how dpkg reports the result, and how to get a removal moving again when it stops halfway.
Find the Package Name Before You Remove It
apt works with package names, and the package name is not always the name on your applications menu. A program installed as a snap or a flatpak is invisible to apt, so confirm the name before you build a removal command around it.
Filter the installed list down to the name you think you want.
apt list --installed 2>/dev/null | grep -i boxes

The output line gives you the name, the archive it came from, the version, the architecture, and the installed marker. The redirect on the first command drops apt’s warning that its output is not a stable scripting interface, which is only noise here.
When you want the full inventory instead of one match, apt can list every installed package with its version and origin.
If the name returns nothing, apt did not install it, and the removal belongs to whichever tool did.
Remove a Package With apt remove
apt prints what it intends to delete before it deletes anything, along with the disk space that frees and any dependency left without an owner.
sudo apt remove -y boxes

The y flag skips the confirmation prompt, which is safe once you have read the plan. Leave it off and apt stops on a yes or no question before it touches anything.
apt and apt-get accept the same arguments for a removal, and they differ mainly in the output they print. The differences between the two front ends matter when you script a removal, because only one of them is built for that.
In this output boxes sits under the packages to be removed, and libpcre2-32-0 is flagged as automatically installed and no longer required. The second line names a dependency that will be left without an owner once boxes is gone.
To see the plan without committing to it, run the same command with the simulate flag.
apt remove -s boxes
Nothing was locked and nothing changed, which is what the simulation note at the top of that output is saying.
What apt remove Leaves Behind
apt remove deletes the packaged files and leaves the modified configuration where it is, so a removal you did not mean can be undone by installing the package again.
List the package you just removed to see the state it is sitting in.
dpkg -l boxes

The rc status on the left is two letters doing separate work. The r says the package is marked for removal and the c says its configuration files are still on disk.
Those letters describe the state of every package on the machine. apt drives dpkg, which is the tool that writes them and the only place to read them back.
| Status | What it means |
|---|---|
| ii | installed and working |
| rc | removed, with the configuration files still on disk |
| iU | unpacked but not configured |
| iF | half-configured |
| un | not installed |
Reach for apt remove when the package might come back, and for apt purge when it will not.
The configuration file stays on disk after the removal, at its original size.
ls -l /etc/boxes/boxes-config

Reinstalling the package would read that file back and restore the settings exactly as they were. That is the whole reason apt keeps it.
Purge the Package and Its Configuration
apt purge removes the package and the configuration files it left behind. Reach for it when the package is not coming back.
sudo apt purge -y boxes

The asterisk after boxes marks every package apt intends to purge rather than remove. On a package that is still installed, purge deletes the files and the configuration in one pass, and the closing line names the configuration it cleared.
Verify with the same command you used before.
dpkg -l boxes

dpkg has nothing left to report, so the package name returns no row at all.
Purge reaches packages that are already removed, so one left in rc state since last month can be purged today without installing it again first.
Clear the Dependencies apt remove Leaves Behind
A removal rarely takes its dependencies with it. apt keeps them because another installed package might still need them, and it says so in the plan when nothing does.
sudo apt autoremove -y

autoremove only touches packages apt installed on another package’s behalf. Anything you installed yourself stays put, which is what makes it safe to run after a removal.
The downloaded package files in the cache are the other layer of leftovers, and the two cache commands do not clear the same things.
| Cache command | What it removes |
|---|---|
| apt clean | every downloaded package file in /var/cache/apt/archives |
| apt autoclean | only the packages apt can no longer download |

apt clean empties that cache and leaves nothing behind but the lock file, while autoclean keeps whatever apt can still download. Clearing unused packages on a machine you have maintained for a while is the same three commands at a larger scale.
Fix a Removal That Stops Halfway
A removal can fail for reasons that have nothing to do with the package you named. The error text says which one it is.
The lock file is the most common. Another apt or dpkg process holds it, and a second command cannot start until the first one finishes. Clearing the dpkg frontend lock is a matter of finding that process rather than deleting the file.
An error code (1) points at a package script that failed while dpkg was running, usually because an earlier install never finished, and the dpkg error code (1) fix starts by reconfiguring the package that is stuck.
Held or broken dependencies are the third failure. Let apt solve the dependency graph in place, and resolve the held broken packages before you try the removal again.
sudo apt --fix-broken install
That command and the shorter apt -f install are the same option, and my dry run on a healthy database reported nothing to do.
Do not delete files out of /var/lib/dpkg by hand. That directory is the database every apt and dpkg command reads, and a hand-edited one turns a stuck removal into a broken system.
When apt Is Not the Package Manager
Snap packages and flatpaks live outside apt, so apt will not remove them. If a program you use every day does not appear in the installed list, one of these tools put it there.
| Tool | Removal command | What it manages |
|---|---|---|
| snap | snap remove <name> | snap packages |
| flatpak | flatpak uninstall <app-id> | flatpak applications |
Run snap list or flatpak list to confirm the name first, then read how snaps work if you want to know what the sandbox keeps in your home directory.
The Plus and Minus Suffixes
apt accepts a plus or a minus sign directly after a package name to override the action the command names.
Turning a purge into an install is the strange consequence.
sudo apt purge -y boxes+

apt counted boxes and its dependency as newly installed and set both of them up, even though the command asked for a purge. The apt manual says a plus after the name installs the package while a minus removes it, whichever action the command itself names.
Common Questions About Removing Packages
What is the difference between apt remove and apt purge?
apt remove deletes the package files and leaves the configuration files on disk. apt purge deletes the package files and the configuration.
How do I remove configuration files left by a package I already removed?
Run apt purge with the package name. A package that dpkg reports with an rc status can be purged without installing it again.
What does the rc status mean in dpkg -l output?
The package files have been removed and the configuration files are still on disk, so reinstalling the package would restore the previous settings.
How do I remove dependencies that apt remove left behind?
Run sudo apt autoremove. It deletes the packages apt installed automatically for another package and leaves packages you installed yourself alone.
Does apt purge delete files in my home directory?
No. Purge clears the package files and the system configuration, and it leaves anything stored in your home directory untouched.
How do I uninstall a package when apt cannot find it?
Check whether a snap or a flatpak installed it. Use snap remove for snaps and flatpak uninstall for flatpaks.
Both manual pages below cover those commands in more depth, and both are worth keeping if you manage packages often.
References
- Ubuntu apt manual page for the remove, purge, and autoremove commands and the plus and minus suffixes.
- Debian apt-get manual page for purge, autoclean, and the fix-broken option in more depth.
