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.
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.
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.
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.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT