Package removed — but config folders stayed behind. Or dependencies went nowhere and are still taking up space. Or something important got removed along with it. Here is how to clean the system properly depending on the distribution, and what to do with what remains.
Debian / Ubuntu / Mint: apt
Remove a Package, Keep Configs
sudo apt remove package_name
The package is removed, configuration files stay in the system. Useful if you plan to reinstall — settings will be preserved.
Remove a Package and Its Configs: purge
sudo apt purge package_name
Clean removal: the binary goes, the configs in /etc go. The user's home directory (~/.config/appname) is not touched — it needs to be deleted manually.
Find and Remove Leftovers From Already-Deleted Packages
After apt remove, configs can linger for a long time. Find everything in 'removed but not purged' status:
dpkg --list | grep '^rc'
Lines starting with rc — packages removed, configs still alive. Purge everything at once:
sudo apt purge $(dpkg --list | grep '^rc' | awk '{print $2}')
Remove Unused Dependencies
After removing a package, its dependencies stay in the system. Remove everything that became unnecessary:
sudo apt autoremove
Running this after every remove is a good habit.
Clear the Downloaded Package Cache
Downloaded .deb files accumulate in /var/cache/apt/archives/:
sudo apt clean
Deletes everything. Or remove only outdated versions (keep current):
sudo apt autoclean
Dry Run Before Removing
See what would be removed without actually doing it:
sudo apt remove --dry-run package_name
Red Hat / CentOS / Rocky Linux / AlmaLinux: dnf and yum
Modern systems (RHEL 8+, Fedora) use dnf. Older ones use yum. Syntax is identical.
Remove a Package
sudo dnf remove package_name
dnf remove by default offers to remove dependencies that became unnecessary — shows the list and asks for confirmation.
Remove Without Confirmation
sudo dnf remove -y package_name
Clean Up Unused Dependencies
sudo dnf autoremove
Find a Package by the File It Installed
If you need to remove a package but do not know its name — find it by file:
rpm -qf /usr/bin/htop
Outputs the package name. Then remove it.
Remove a Package Group
sudo dnf groupremove "Development Tools"
Arch Linux / Manjaro: pacman
Remove a Package
sudo pacman -R package_name
Removes only the package itself, dependencies stay.
Remove a Package and Its Dependencies
sudo pacman -Rs package_name
-s (recursive) removes dependencies no longer needed by any other package.
Full Cleanup With Configs
sudo pacman -Rns package_name
-n removes config files, -s removes unneeded dependencies. The most thorough removal option.
Find and Remove Orphaned Packages
Packages installed as dependencies that nothing depends on anymore:
sudo pacman -Qdtq | sudo pacman -Rns -
openSUSE: zypper
sudo zypper remove package_name
Remove with dependencies:
sudo zypper remove --clean-deps package_name
Snap Packages
Snap packages are managed separately from the system package manager.
List installed snap packages:
snap list
Remove a snap package:
sudo snap remove package_name
By default snap keeps several revisions. Remove a specific revision:
sudo snap remove package_name --revision=123
Remove all saved revisions except the active one:
snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do
sudo snap remove "$snapname" --revision="$revision"
done
Flatpak
List installed:
flatpak list
Remove:
sudo flatpak uninstall com.spotify.Client
Remove including user data:
sudo flatpak uninstall --delete-data com.spotify.Client
Clean up unused runtimes:
sudo flatpak uninstall --unused
Find What Is Taking Up Space Before Cleaning
Before mass removal — useful to see what actually occupies space.
Top 15 largest packages (Debian/Ubuntu):
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | head -15
Quick Reference
| Distribution | Remove | Remove With Configs | Clean Dependencies |
|---|---|---|---|
| Debian/Ubuntu | apt remove pkg | apt purge pkg | apt autoremove |
| RHEL/CentOS | dnf remove pkg | — | dnf autoremove |
| Arch Linux | pacman -R pkg | pacman -Rns pkg | pacman -Qdtq | pacman -Rns - |
| openSUSE | zypper remove pkg | — | zypper remove --clean-deps pkg |
| Snap | snap remove pkg | snap remove pkg | — |
| Flatpak | flatpak uninstall pkg | flatpak uninstall --delete-data pkg | flatpak uninstall --unused |