The accepted answer will rarely work if you have an issue with the CDN (content delivery network—the caches/mirrors around the world containing the apt lists and packages). It will work if a) you are using a PPA or local mirrors or b) have just a single mismatch to resolve.
Note: if you have the specific error message given in the log in the question above, the accepted answer should always work. But there are several other questions that have been closed as duplicates of this one where the accepted answer is insufficient.
It doesn't hurt to try, though, so start with:
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
This might be sufficient to proceed with sudo apt-get upgrade
or other follow-up commands.
But if it doesn't work...
You may get "Hash sum mismatch" errors from that command, too. If this happens, run:
sudo apt-get update --fix-missing
It is possible that even this command will throw "Hash sum mismatch" errors, because the issue can come from transient network content errors. If so, continue to re-run the above --fix-missing
command until it completes successfully. For example, like:
until sudo apt-get update --fix-missing; do echo trying again; done
(It should make progress with each run of apt-get update --fix-missing
; if successive runs are not reducing the errors towards zero, press Ctrl-c to interrupt the loop. Then go back to the beginning of this answer with removing the contents of /var/lib/apt/lists
and try again.)
After this, the update may work, but to be sure, first run apt-get clean
, as so:
sudo apt-get clean
sudo apt-get update
Note that if you're doing this in preparation for an apt-get upgrade
, it is possible (even likely, if you had enough mismatches to require updating several times) the upgrade will fail with "Hash sum mismatch" errors of its own. If so, add --fix-missing
to your upgrade command:
sudo apt-get clean
sudo apt-get upgrade --fix-missing
and try again. (apt-get upgrade
with --fix-missing
will also try holding back failing packages and continuing others, so you should see some additional progress from running this at least once.)
But if it still doesn't work...
Like the earlier until sudo...
command, you may get some further progress by repeating this command (always preceded by the clean
command above), which you can even automate with
until (sudo apt-get clean; sudo apt-get upgrade --fix-missing --yes); do echo trying again; done
but, usually, it will upgrade most of the upgradable packages the first time you run it with --fix-missing
and after that get stuck on the same packages, making no further progress. At that point, you'll need to go back up to the beginning with the sudo rm -rf /var/lib/apt/lists/*
and try again. It is worth trying this whole process two or three times, especially if you have dozens or hundreds of upgradable packages.