How to Fix ‘Hash Sum Mismatch’ Error During apt update in Ubuntu

Running standard system maintenance on Ubuntu by typing sudo apt update typically refreshes software indices smoothly. However, encountering a sudden termination accompanied by bold red alerts reading “E: Failed to fetch … Hash Sum mismatch” or “Hashes of expected file: – Filesize:… SHA256:… Hashes of received file:…” prevents packages from downloading and halts software upgrades entirely.

A “Hash Sum Mismatch” error indicates that the cryptographic checksum of the package list downloaded by your system does not match the expected hash defined in the upstream repository Release file. This discrepancy is rarely a sign of a malicious man-in-the-middle attack. Instead, it is almost universally caused by aggressive HTTP proxy caching on your ISP or local network, out-of-sync mirror servers serving partial package manifests, or corrupted cached index files inside /var/lib/apt/lists/. Follow these step-by-step methods to clear corrupted package manifests and restore reliable APT updates.

Method 1: Purge the Local APT Lists Directory and Refresh

APT maintains cached repository indices inside /var/lib/apt/lists/. If an interrupted network connection corrupts an in-flight file, APT will consistently fail hash comparisons. Deleting these cached files forces APT to download a pristine index.

  1. Open your terminal by pressing Ctrl + Alt + T.
  2. Purge the cached package archives:
    sudo apt clean
  3. Remove all downloaded repository lists:
    sudo rm -rf /var/lib/apt/lists/*
  4. Recreate the lists directory structure and refresh repository metadata:
    sudo apt update
  5. Verify that the package indices fetch completely without any hash mismatch warnings.

Method 2: Disable HTTP Pipeline Caching in APT Configuration

Certain transparent ISP proxies, corporate firewall gateways, and local routers interfere with HTTP pipelining, serving stale or truncated cached files that fail checksum tests. Creating a custom APT configuration directive disables pipelining and forces fresh downloads.

  1. In your terminal, create a new configuration file in /etc/apt/apt.conf.d/:
    sudo nano /etc/apt/apt.conf.d/99fix-hash-mismatch
  2. Paste the following configuration directives into the editor:
    Acquire::http::Pipeline-Depth "0";
    Acquire::http::No-Cache "true";
    Acquire::BrokenProxy "true";
  3. Press Ctrl + O followed by Enter to save the file, then press Ctrl + X to exit nano.
  4. Execute sudo apt update to confirm the fix. The directives ensure APT communicates directly with mirrors without caching intermediate fragments.

Method 3: Switch to the Main Canonical Ubuntu Mirror

Regional country mirrors (e.g., us.archive.ubuntu.com or uk.archive.ubuntu.com) synchronise on staggered schedules. If a regional mirror is currently undergoing a multi-gigabyte rsync update while you run apt update, metadata indices and binary packages will temporarily desynchronise.

  1. Backup your existing sources list:
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
  2. Edit your sources list:
    sudo nano /etc/apt/sources.list
  3. Replace your regional mirror prefix (such as us.archive.ubuntu.com) with the primary root mirror:
    archive.ubuntu.com
  4. Alternatively, on modern Ubuntu systems, switch your mirror graphically: open Software & Updates, click the Download from dropdown, select Main server, and click Close.
  5. Run sudo apt update to rebuild indices against the primary Canonical archive.

Method 4: Force IPv4 Protocol for Repository Downloads

Incomplete or broken IPv6 routing configurations on home routers can cause packet dropouts during large archive downloads, resulting in truncated files that fail SHA256 checks.

  1. Force APT to query mirrors strictly over IPv4 by running:
    sudo apt update -o Acquire::ForceIPv4=true
  2. If this resolves the error, make the change permanent by adding a configuration directive:
    echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
  3. Proceed with your software upgrades normally:
    sudo apt upgrade

Ubuntu Hash Sum Mismatch Troubleshooting Reference Table

Consult the diagnostic reference matrix below to address specific APT hash error conditions:

Error Context Probable Root Cause Remedial Solution
Hash mismatch on official Canonical repos Corrupted local list cache in /var/lib/apt/lists/ sudo rm -rf /var/lib/apt/lists/* && sudo apt update
Mismatch persists despite clearing local lists Transparent ISP proxy caching stale HTTP chunks Add Acquire::http::Pipeline-Depth “0”; to apt.conf.d
Error isolated to a specific regional mirror Regional archive desynchronised during upstream sync Switch repository to main “archive.ubuntu.com”
Intermittent mismatch during package download Flaky IPv6 MTU packet fragmentation Pass -o Acquire::ForceIPv4=true to apt update
Hash mismatch on third-party PPA repository Developer updated package files without updating Release Remove and re-add PPA via add-apt-repository -r

Cleaning Up Temporary Apt Configuration Overrides

Once your repository indices update smoothly and software upgrades conclude, you can retain the /etc/apt/apt.conf.d/99fix-hash-mismatch file without adverse performance impact. The pipeline depth setting incurs only a negligible millisecond latency difference during updates while permanently protecting your system against aggressive transparent caching proxies.

Get the best tech tips delivered straight to your inbox.

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