How to Clean the Apt Package Cache to Reclaim Disk Space in Ubuntu

Every time you install application updates, software packages, or security patches in Ubuntu, the native APT package manager downloads pre-compiled .deb archive files from canonical repositories. By default, Ubuntu retains these downloaded package archives inside a local cache on your root filesystem at /var/cache/apt/archives/. Over several months of routine updates, this package cache can silently swell to consume 5, 10, or even 20 gigabytes of precious storage. Learning how to clean your APT cache quickly restores valuable drive space without harming installed applications.

Why Ubuntu Stores Downloaded Packages

The APT archive cache serves a practical purpose: it holds downloaded installers so that if a package installation is interrupted or you need to reinstall a utility without an active internet connection, Ubuntu can draw directly from local disk storage. However, once a software package is successfully configured and running, keeping the installer file on disk is rarely necessary for everyday desktop users. Cleaning these archive directories does not delete your programs or remove personal user configurations.

How to Check the Size of Your Current APT Cache

Before purging cached archives, you can easily inspect how much disk space the directory currently occupies:

  1. Press Ctrl + Alt + T on your keyboard to open the terminal.
  2. Run the following disk usage command:
    du -sh /var/cache/apt/archives
  3. The terminal will return a human-readable output (such as 4.8G or 12G), displaying the total volume of storage currently tied up by cached installer files.

Cleaning the APT Cache: Clean vs. Autoclean

Ubuntu provides two built-in commands tailored for clearing cached installation packages depending on your maintenance preferences:

  • sudo apt clean: Completely purges all cached .deb package files from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/, leaving only the lock file. This is the recommended choice when you need to reclaim maximum disk space immediately.
  • sudo apt autoclean: Deletes only obsolete package files that are no longer available in Ubuntu’s active software repositories. Any installer packages that match your currently installed version are preserved in case you need to reinstall offline.

Step-by-Step Commands to Clean Your Package Cache

To safely clean your package archives and remove obsolete package dependencies in one quick maintenance session:

  1. In your open terminal, execute the full clean command:
    sudo apt clean
  2. Type your administrative user password when prompted and press Enter. APT will instantly delete all cached archive binaries.
  3. Next, remove orphaned software libraries and old Linux kernels that were automatically installed as dependencies but are no longer needed by any active program:
    sudo apt autoremove --purge
  4. Press Y when prompted to confirm the uninstallation of lingering dependencies.
  5. Verify your reclaimed space by running df -h / to check your root partition capacity.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.