How to Remove Unused Packages on Ubuntu

Remove unused packages on Ubuntu with apt autoremove for orphaned dependencies, apt clean and autoclean for download cache, purge rc config leftovers, protect apps with apt-mark manual, and prune old Snap revisions—without confusing unused with obsolete.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

Remove unused packages on Ubuntu banner with apt autoremove command and cleanup icons

After you uninstall software or finish an upgrade, Ubuntu often still has leftovers: dependency packages nothing needs anymore, downloaded .deb files in the apt cache, configuration directories from purged apps, or old Snap revisions. The phrase “unused packages” shows up in forum posts and upgrade prompts, but it does not always mean the same thing.

This guide separates those cases and shows the safe, official cleanup path first—apt autoremove—plus cache cleanup, rc config purge, protecting apps with apt-mark manual, and optional usage-based tools. I ran the commands on Ubuntu 25.04 and kept real output below.

Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; amd64.

IMPORTANT
Unused (autoremove), obsolete (post-upgrade /now packages), apt cache (downloaded .deb files), and rc configs are four different cleanups. Mixing them up is how people delete apps they still open every day—read the comparison table before bulk commands.

Unused vs obsolete vs cache vs rc

Term What it is Safe default command
Unused dependencies Auto-installed packages nothing depends on sudo apt autoremove
Obsolete packages Installed version missing from all apt sources apt list '?obsolete' then review—see remove obsolete packages
APT download cache .deb files in /var/cache/apt/archives/ sudo apt autoclean or sudo apt clean
rc leftovers Config files after apt remove sudo apt purge packagename
Old Snap revisions Disabled snap builds kept for rollback sudo snap remove name --revision=REV
Rarely used apps (heuristic) Low popularity-contest score—not orphan-safe Manual review only

Ask Ubuntu guidance on autoremove and safely removing unused packages both stress the same point: APT cannot know which applications you still want—it only tracks automatic vs manual install flags and dependency graphs.


What do you want to clean?

Goal Jump to
Remove orphaned dependency packages (main task) apt autoremove
Preview before deleting anything Dry-run autoremove
Stop autoremove from deleting an app you need Protect with apt-mark manual
Free disk from downloaded .deb files apt clean and autoclean
Remove leftover config after uninstall Purge rc packages
Drop old Snap revisions Prune disabled Snap revisions
Find rarely touched packages (advanced) popularity-contest
Post-release-upgrade stale packages Obsolete packages
Uninstall a specific app you chose to remove How to remove software on Ubuntu

Prerequisites

  • Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested)—see check Ubuntu version.
  • sudo for remove, purge, and cache commands.
  • Read-only listing works without root; simulations still benefit from sudo when locks matter.

Related: apt command, dpkg command, list installed packages.


Remove unused dependencies with apt autoremove

When you install a package, APT pulls in dependencies and marks them automatically installed. If you later remove the parent app, those libraries may sit unused. apt autoremove removes automatic packages no other installed package still requires.

Preview first (see next section), then run:

bash
sudo apt autoremove

Add --purge to drop configuration files for those dependencies too:

bash
sudo apt autoremove --purge

On the test host, a dry-run proposed removing one orphaned library after a PPA package was removed earlier:

text
The following packages will be REMOVED:
  libtorrent-rasterbar2.0
0 upgraded, 0 newly installed, 1 to remove and 31 not upgraded.

With --purge, the same simulation showed a Purg line instead of Remv—configs go with the package.

NOTE
autoremove is the cleanup step Ubuntu offers after apt remove when it prints “The following packages were automatically installed and are no longer required.” Running it regularly after uninstalls is enough for most desktops and servers.

Preview with dry-run first

Never confirm autoremove blind on a machine you care about. Simulate:

bash
sudo apt-get -s autoremove

Or with purge:

bash
sudo apt-get -s autoremove --purge

The -s flag means simulate—no packages change. Read every name in “The following packages will be REMOVED”.

If the list is empty:

text
0 upgraded, 0 newly installed, 0 to remove and 31 not upgraded.

That is a healthy sign—nothing APT considers an orphaned automatic dependency right now.


Protect a package from autoremove

Ask Ubuntu: safely removing unused packages describes a common trap: autoremove proposes deleting an application you still use because APT marked it automatic—for example when it was installed as a dependency of a metapackage you removed, or a GUI installer set the wrong flag.

Mark a package manual so autoremove skips it:

bash
sudo apt-mark manual packagename

Verify:

bash
apt-mark showmanual | grep -i packagename

List packages still marked automatic (candidates for autoremove when nothing needs them):

bash
apt-mark showauto | head

On the test host, 324 packages were manual and 2256 automatic—most of your system is dependencies, which is normal.

To mark a dependency automatic again (only when you are sure):

bash
sudo apt-mark auto packagename

Clear the APT download cache

These commands do not remove installed programs. They delete cached .deb files APT downloaded during installs and upgrades.

Check cache size:

bash
du -sh /var/cache/apt/archives/

On the test host that reported 627M.

autoclean — delete outdated cache files only

Removes .deb files that are no longer downloadable from your configured sources (superseded versions):

bash
sudo apt autoclean

Simulation showed lines like:

text
Del mongodb-org-server 8.0.26 [43.1 MB]
Del mongodb-mongosh 2.8.3 [64.3 MB]
Del mongodb-database-tools 100.17.0 [60.7 MB]

clean — wipe the entire download cache

Deletes all package files from /var/cache/apt/archives/ (except lock files):

bash
sudo apt clean

Simulation output:

text
Del /var/cache/apt/archives/* /var/cache/apt/archives/partial/*
HINT
Run autoclean routinely; use clean when you need maximum space back and do not mind re-downloading .deb files on the next upgrade. Neither replaces autoremove.

Purge rc configuration leftovers

After apt remove, packages can remain in rc state—removed, but config files linger:

bash
dpkg -l | grep '^rc'

Sample rows on the test host:

text
rc  apg                    2.2.3.dfsg.1-7   amd64  Automated Password Generator
rc  cups-pk-helper         0.2.6-2.1        amd64  PolicyKit helper to configure cups
rc  evolution-data-server  3.56.0-1         amd64  evolution database backend server

Count:

bash
dpkg -l | grep -c '^rc'

That returned 26 entries—small on disk, but easy to clean.

Purge one:

bash
sudo apt purge apg

Bulk purge after review:

bash
dpkg -l | awk '/^rc/{print $2}' | xargs -r sudo apt purge -y

This is config cleanup, not dependency orphan removal.


Prune old Snap revisions

Snap keeps older disabled revisions for rollback. They are not apt packages and autoremove does not touch them.

List disabled revisions:

bash
snap list --all | awk '/disabled/{print $1, $2, $3}'

Example lines:

text
firefox 152.0.1-1 8521
gnome-42-2204 0+git.837775c-sdk0+git.7b07595 226
mesa-2404 25.0.7-snap211 1165

The test host had 7 disabled revisions.

Remove one revision (keep the current enabled build):

bash
sudo snap remove firefox --revision=8521

Repeat per line, or script carefully—never remove the revision you are currently running.


Optional: find rarely used packages

popularity-contest / popcon-largest-unused

The popularity-contest package reports which files on your system were accessed recently. popcon-largest-unused lists packages with low participation scores—a hint for manual review, not a safe bulk-delete list.

Install:

bash
sudo apt install popularity-contest

Generate the data file (required once):

bash
sudo popularity-contest | sudo tee /var/log/popularity-contest > /dev/null

Run the report:

bash
popcon-largest-unused | head -15

Example output:

text
63459 libclang-cpp18
37925 vim-runtime
36607 libclang1-19
17870 libc6-dbg
16788 locales
14892 ieee-data
14691 crash
12757 memtest86+
12614 gdb
12472 libgtk-4-bin
9936 firmware-sof-signed
9244 m17n-db
8210 bpftrace
7345 papers
5504 orca

High numbers mean more popularity-contest votes—not “safer to delete.” Removing locales or libc6-dbg because they appear here would break the system.

Legacy and third-party tools

Tool Status on Ubuntu 25.04 Notes
deborphan Not in default repositories Historical orphan finder; Ask Ubuntu mentions it—prefer autoremove today
gtkorphan Not in default repositories Old GUI orphan tool; discontinued on recent Ubuntu
unusedpkg (GitHub script) Third-party Ranks by file idle time; Ask Ubuntu links it—read the script and verify timestamps before any apt remove
WARNING
Do not pipe popcon-largest-unused, deborphan, or unusedpkg output straight into xargs apt remove. Ubuntu cannot infer which packages you still need—review each name and check apt-cache rdepends packagename when unsure.

Troubleshooting

Symptom Likely cause What to try
autoremove wants to delete an app you use Package marked automatic sudo apt-mark manual packagename
autoremove removes almost nothing No orphaned automatic deps Normal—run after uninstalling larger apps
autoclean / clean did not free much space Cache already small Check du -sh /var/cache/apt/archives/; look at Snap, logs, old kernels
Freed cache but apps still huge Cache ≠ installed packages Use list installed packages size sort; remove apps you do not need
Many packages still “unused” after autoremove Confusing unused with obsolete apt list '?obsolete'—see obsolete guide
rc entries return after purge Metapackage or reinstall pulled configs sudo apt purge again; check for snap/flatpak duplicate
popcon-largest-unused warns missing file No survey log yet sudo popularity-contest | sudo tee /var/log/popularity-contest
deborphan not found Dropped from current Ubuntu releases Use apt autoremove and manual review

References


Summary

On Ubuntu, remove unused dependency packages with sudo apt autoremove (optionally --purge) after you apt-get -s autoremove and read the list. That is what upgrade wizards and Ask Ubuntu cleanup answers mean by unused packages—not every program you have not opened lately.

apt autoclean and apt clean only shrink the download cache under /var/cache/apt/archives/—they do not uninstall applications. Purge rc configs separately, prune disabled Snap revisions when you need space, and use apt-mark manual when autoremove targets software you still rely on. For packages left behind after a release upgrade, use the obsolete packages guide instead of autoremove alone.


Frequently Asked Questions

1. What does apt autoremove do on Ubuntu?

apt autoremove uninstalls packages APT marked as automatically installed when nothing else depends on them anymore—typically libraries left behind after you removed an application. It does not remove packages you explicitly installed unless they were wrongly marked automatic.

2. Is apt autoclean the same as autoremove?

No. autoclean deletes outdated .deb files from /var/cache/apt/archives that can no longer be downloaded. autoremove uninstalls installed packages. clean wipes the entire apt download cache. None of these three commands do the same job.

3. How do I preview what autoremove will delete?

Run sudo apt-get -s autoremove or sudo apt -s autoremove before confirming. Read every package name in the simulation output—autoremove can remove a dependency another tool still needs if APT dependency tracking disagrees with how you use the system.

4. Why does autoremove want to remove an app I still use?

APT may have marked the package automatic—common when it was pulled in as a dependency or installed through a metapackage you later removed. Run sudo apt-mark manual packagename to protect it, then rerun autoremove.

5. What is the difference between unused and obsolete packages?

Unused (autoremove) means auto-installed dependencies nothing requires anymore. Obsolete means the installed version is no longer in any configured apt repository—common after release upgrades. See remove obsolete packages on Ubuntu for ?obsolete cleanup.

6. What are rc packages and should I purge them?

rc means the package was removed but configuration files remain in /etc. They are not running software—purge them with sudo apt purge packagename or bulk purge rc names to reclaim a small amount of disk space.

7. Is deborphan still available on Ubuntu?

deborphan is not in the Ubuntu 25.04 repositories and is largely unmaintained. Prefer apt autoremove for dependency cleanup and manual review with apt-mark showmanual for packages you care about.

8. How do I remove all unused dependencies at once?

Run sudo apt autoremove after reviewing the list, or sudo apt autoremove --purge to drop config files too. Combine with sudo apt autoclean for cache and purge rc leftovers separately—there is no single safe command that removes every kind of leftover on a production system without review.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …