Clean orphaned and unused packages on Ubuntu to free storage and RAM

A concise how-to for removing leftover dependencies, clearing package caches, and using deborphan to find orphaned libraries so Ubuntu reclaims disk space and stays lean.

What the video covers

Commands for package cleanup using apt and optional deborphan; safe for general desktop/server Ubuntu systems. Does not cover distribution-specific package managers or automated GUI tools.

Watch the video on YouTube

Step-by-step instructions

  1. Open a terminal
    Use your desktop's terminal app or connect via SSH for remote systems.
  2. Update package lists
    Run: sudo apt update — this ensures apt knows the latest package state before removing anything.
  3. Remove unused dependencies
    Run: sudo apt autoremove — this removes packages that were installed as dependencies but are no longer required.
  4. Clean cached package files
    Run: sudo apt clean — this deletes downloaded package files stored in the apt cache to free disk space.
  5. Remove partially installed or obsolete package files
    Run: sudo apt autoclean — this removes cached package files that can no longer be downloaded (obsolete).
  6. Manually remove or purge specific packages
    To remove a package: sudo apt remove package-name. To also remove configuration files: sudo apt purge package-name. Use apt list –installed to confirm package names before removal.
  7. Optional: find orphaned libraries with deborphan
    For deeper cleanup, install deborphan (sudo apt install deborphan), run deborphan to list orphaned libs, and carefully remove any you don't need (sudo apt remove package-name). This step is for advanced users—review results before removing.
  8. Optional: clear thumbnail cache
    To free user cache space, remove thumbnail files: rm -rf ~/.cache/thumbnails/* (this affects only user thumbnails).

Watch the video

Video thumbnail for Clean orphaned and unused packages on Ubuntu to free storage and RAM Play tutorial

Watch on YouTube

Why it matters

Leftover dependencies, cached packages, and unused libraries accumulate over time and consume disk space. Regular cleanup recovers storage and can reduce background resource use, improving stability.

Check your result

After running the steps, confirm reclaimed space with df -h and review installed packages with apt list –installed. Reboot if you removed low-level libraries that may require a restart.

Troubleshooting

If a removal fails due to broken packages, run sudo apt –fix-broken install and then retry autoremove/clean. If a needed package was removed accidentally, reinstall it with sudo apt install package-name.