How to fix E: The package cache file is corrupted in APT

APTBEGINNERMEDIUMUpdated Apr 4, 2026· 303 views

This error occurs when apt's package cache at /var/lib/apt/lists/ is corrupted or contains invalid files. This typically happens after interrupted downloads, filesystem errors, or incomplete updates. The fix is to safely clear the corrupted cache and rebuild it with apt update.

Quick fix

Fixes E: The package cache file is corrupted

sudo rm -rf /var/lib/apt/lists/*
  1. Clear the corrupted cache
  2. Recreate the partial directory if it was deleted
  3. Check for filesystem corruption
  4. Use apt clean and apt autoclean
apt — error
sudo rm -rf /var/lib/apt/lists/*
E: The package cache file is corrupted

What this error means

The apt package cache stores metadata about available packages and their dependencies. When apt reads this cache, it validates file integrity using checksums. If a file is corrupted (incomplete download, disk I/O error, or filesystem damage), apt cannot parse it and reports this error. The cache is essential for apt to know which packages are available and how they relate to each other. Without a valid cache, apt cannot resolve dependencies or install packages.

Typical symptoms

  • apt update or apt install commands fail immediately with the cache error
  • Unable to install new packages or update existing ones
  • Error message mentions "The package cache file is corrupted" or "it has the wrong hash"
  • All package management operations are blocked
  • The error may reference a specific file in /var/lib/apt/lists/
  • Sometimes accompanied by "Structure needs cleaning" messages indicating filesystem corruption

Common causes

  1. Interrupted download during apt update (power loss, network interruption, or manual cancellation)
  2. Filesystem corruption on the disk or storage device (especially on SD cards or USB drives)
  3. Incomplete or partially-written cache files from a previous failed operation
  4. APT upgrade that left cache incompatible with the new version (version hash mismatch)
  5. I/O errors or bad sectors on the storage device
  6. NAND flash issues on Raspberry Pi or embedded systems

How to fix "E: The package cache file is corrupted"

1Clear the corrupted cache

Remove all corrupted cache files from /var/lib/apt/lists/. This is the fastest and safest solution:

bash
sudo rm -rf /var/lib/apt/lists/*

Warning: Make sure you include the * at the end. Omitting it will delete the entire /var/lib/apt/lists/ directory itself, which may not be recreated.

After clearing, rebuild the cache:

bash
sudo apt update

This will download fresh package metadata from your configured repositories.

2Recreate the partial directory if it was deleted

If the previous step deleted /var/lib/apt/lists/ entirely (unlikely but possible), recreate the partial subdirectory that apt needs:

bash
sudo mkdir -p /var/lib/apt/lists/partial
sudo chmod 755 /var/lib/apt/lists
sudo apt update

This ensures apt has the necessary directory structure to download fresh metadata.

3Check for filesystem corruption

If clearing the cache doesn't resolve the issue, especially if you see "Structure needs cleaning" errors, your filesystem itself may be corrupted. Check and repair it:

bash
sudo fsck -f /dev/sda1

Replace /dev/sda1 with your actual root partition. You may need to boot into recovery mode or use a live USB for this. After fsck completes, reboot and try apt again.

Note: This is primarily a concern on Raspberry Pi or embedded systems with SD cards. Desktop/server users rarely need this step unless hardware is failing.

4Use apt clean and apt autoclean

Before manually clearing the cache, try apt's built-in cleanup commands, which are safer:

bash
sudo apt clean
sudo apt autoclean
sudo apt update

apt clean removes all package cache files, while apt autoclean removes only old versions. These are reversible operations. If they don't resolve the issue, proceed to the full cache clear above.

5Verify and update sources.list

After rebuilding the cache, ensure your software sources are valid:

bash
sudo apt-cache search . | head
sudo apt list --upgradable

If you still encounter errors, review your /etc/apt/sources.list and /etc/apt/sources.list.d/ files:

bash
sudo nano /etc/apt/sources.list

Check for duplicate, malformed, or outdated repository entries. Make sure all URLs are correct and your system architecture matches the available packages.

6Check system storage and disk health

Package cache corruption can indicate underlying hardware problems. Check available disk space:

bash
df -h /var/lib/apt

Ensure you have at least 100MB free. If storage is full or nearly full, delete old packages and temporary files:

bash
sudo apt clean
sudo apt autoclean
sudo journalctl --vacuum=1w

For Raspberry Pi or systems with SD cards, monitor SMART health:

bash
sudo smartctl -a /dev/sda

If you see SMART errors, your storage device may be failing and needs replacement.

Advanced notes

Hash mismatch errors (specifically "it has the wrong hash") typically occur after apt version upgrades. The version number is included in the cache hash computation, so if apt is upgraded and tries to use an old cache generated by a different version, hashes won't match. This is solved by running apt update without any special flags. On Raspberry Pi and embedded systems, SD card wear and power loss during writes are the most common causes of this error. If you experience frequent cache corruption, consider using a high-quality SD card and UPS power backup. PostgreSQL-based systems may also experience this if running low on memory, as apt uses temporary memory buffers. Corrupted cache files cannot be repaired incrementally—they must be removed and re-downloaded. For critical production systems, automate cache rebuilds with periodic apt update runs via cron.

Frequently asked questions

What does "E: The package cache file is corrupted" mean?
The apt package cache stores metadata about available packages and their dependencies. When apt reads this cache, it validates file integrity using checksums. If a file is corrupted (incomplete download, disk I/O error, or filesystem damage), apt cannot parse it and reports this error.
How do I fix "E: The package cache file is corrupted"?
This error occurs when apt's package cache at /var/lib/apt/lists/ is corrupted or contains invalid files. This typically happens after interrupted downloads, filesystem errors, or incomplete updates. The fix is to safely clear the corrupted cache and rebuild it with apt update.
What causes "E: The package cache file is corrupted"?
Interrupted download during apt update (power loss, network interruption, or manual cancellation) Filesystem corruption on the disk or storage device (especially on SD cards or USB drives) Incomplete or partially-written cache files from a previous failed operation
Is the "E: The package cache file is corrupted" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading