"Hash Sum mismatch" during apt install on Raspberry Pi OS: stale index or out-of-sync mirror?
0 reputation · 27 Sept 2020, 03:56 UTC
0 reputation · 27 Sept 2020, 03:56 UTC
On Raspberry Pi OS (Debian-based, bookworm assumed), an apt install or full-upgrade can fail with a Hash Sum mismatch error when the local package index under /var/lib/apt/lists no longer matches the repository's current Release and Packages metadata. The apt toolchain only refreshes this index when apt update runs; it does not check freshness automatically before installing.
The ambiguity is in the root cause. A stale local index is a client-side problem, but the Raspberry Pi-specific repositories and the raspbian archive sync on their own schedules, so a recently updated mirror can transiently disagree with the metadata another client fetched earlier. That makes it unclear whether a given mismatch should be treated as a local cache issue or as a mirror-side inconsistency that will resolve on its own.
Timestamps in /var/lib/apt/lists can be compared against the repository's Release file date to gauge staleness, but that does not distinguish a corrupt partial download from a legitimately mid-sync mirror.
Is there a reliable way to tell from the error output or index state whether the mismatch is local staleness versus a mirror that is mid-sync? Does the diagnosis differ between the raspbian archive and the Raspberry Pi-specific repository? And is clearing the lists directory ever strictly necessary, or is a plain refresh always sufficient when the index is merely old rather than corrupted?
29275 reputation · 27 Sept 2020, 14:11 UTC
You cannot reliably distinguish the two causes from the error text alone — apt reports the same Hash Sum mismatch either way. The practical distinction is behavioral: a stale or partially written local index is fixed permanently by a clean refresh, while a mid-sync mirror keeps failing after a clean refresh and is fixed by switching mirrors or waiting. Clearing /var/lib/apt/lists is not strictly required for a merely old index (apt update overwrites it), but it is the cheapest way to rule out a corrupt partial download, so it is the right first step.
apt downloads a signed Release/InRelease file that lists the expected hashes of every index file, and those indexes in turn list hashes of each .deb. A mismatch means something apt fetched does not match what the signed metadata promised, so apt aborts rather than risk installing corrupted or tampered content. Do not bypass this with insecure options — the check is doing its job.
archive.raspberrypi.org / raspi.list), often via a redirector. These sync on their own schedules, so a mirror can briefly serve a new Release file against old index files. This is the most common cause when the error appears suddenly on a system that worked yesterday.apt update or abrupt power loss (common on SD-card Pis) can leave truncated files in /var/lib/apt/lists.sudo rm -rf /var/lib/apt/lists/*
sudo apt updateapt update completes and the install proceeds, it was a local index problem. Done./etc/apt/sources.list (and /etc/apt/sources.list.d/raspi.list for the Raspberry Pi repo; exact filenames vary between bullseye and bookworm, so check what exists on your system), pick a different official mirror, and rerun apt update. Alternatively, wait an hour and retry — mid-sync mirrors usually converge on their own.dmesg for I/O errors and a filesystem check on the card.Error output vs. index state: comparing timestamps in /var/lib/apt/lists against the repository's Release date tells you the index is old, but as you noted it cannot separate a corrupt partial download from a mid-sync mirror. The clean-refresh test above is the reliable discriminator, not the timestamps.
Raspbian vs. Raspberry Pi repo: the diagnosis is the same, but note which repository the failing file belongs to in the error output — the Raspberry Pi-specific repo is smaller and syncs differently, so only edit the corresponding sources file rather than both.
Is clearing the lists directory ever strictly necessary? For a merely outdated index, no — apt update replaces it. Clearing is only needed to eliminate corrupt partial files, and since you cannot tell those apart from the error alone, doing it once up front is the pragmatic choice.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.