How to fix E: The package cache file is corrupted in APT
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/*- Clear the corrupted cache
- Recreate the partial directory if it was deleted
- Check for filesystem corruption
- Use apt clean and apt autoclean
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
- 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
- APT upgrade that left cache incompatible with the new version (version hash mismatch)
- I/O errors or bad sectors on the storage device
- NAND flash issues on Raspberry Pi or embedded systems
How to fix "E: The package cache file is corrupted"
Remove all corrupted cache files from /var/lib/apt/lists/. This is the fastest and safest solution:
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:
sudo apt updateThis will download fresh package metadata from your configured repositories.
If the previous step deleted /var/lib/apt/lists/ entirely (unlikely but possible), recreate the partial subdirectory that apt needs:
sudo mkdir -p /var/lib/apt/lists/partial
sudo chmod 755 /var/lib/apt/lists
sudo apt updateThis ensures apt has the necessary directory structure to download fresh metadata.
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:
sudo fsck -f /dev/sda1Replace /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.
Before manually clearing the cache, try apt's built-in cleanup commands, which are safer:
sudo apt clean
sudo apt autoclean
sudo apt updateapt 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.
After rebuilding the cache, ensure your software sources are valid:
sudo apt-cache search . | head
sudo apt list --upgradableIf you still encounter errors, review your /etc/apt/sources.list and /etc/apt/sources.list.d/ files:
sudo nano /etc/apt/sources.listCheck for duplicate, malformed, or outdated repository entries. Make sure all URLs are correct and your system architecture matches the available packages.
Package cache corruption can indicate underlying hardware problems. Check available disk space:
df -h /var/lib/aptEnsure you have at least 100MB free. If storage is full or nearly full, delete old packages and temporary files:
sudo apt clean
sudo apt autoclean
sudo journalctl --vacuum=1wFor Raspberry Pi or systems with SD cards, monitor SMART health:
sudo smartctl -a /dev/sdaIf 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
- 📚APT Official Documentation
- 📖Debian Wiki - APT Package Manager(Official Docs)
- 📖Debian Reference - Package Management(Official Docs)
- 📝
- 📝
- 🔗