Apt-Get using Apt-Cacher NG fails to fetch packages with hash sum mismatch

Solution 1:

I would suggest to switch away from APT-cacher-ng and check out Squid-deb-proxy.

APT-cacher-ng has proven to be very buggy in my experience and tons of bug reports are outstanding. Only recently it has been proposed again to get unblocked in Debian now that some major bugs are squashed. For Ubuntu I've switched to Squid-deb-proxy a long time ago and I don't regret it. It's a great alternative and the best APT-cacher I've come around.

For Squid-deb-proxy, just install the package squid-deb-proxy and add allowed destination domains in a new file in /etc/squid-deb-proxy/mirror-dstdomain.acl.d. As a bonus, clients can auto-discover caching-enabled machines in the local network by having the squid-deb-proxy-client package installed.

Solution 2:

You can fix this right now by running:

http://your-cache-server:3142/acng-report.html?abortOnErrors=aOe&byPath=bP&byChecksum=bS&truncNow=tN&incomAsDamaged=iad&purgeNow=pN&doExpire=Start+Scan+and%2For+Expiration&calcSize=cs&asNeeded=an#bottom

This will delete all the broken files in your cache.

To make this permananet, have a look at https://www.unix-ag.uni-kl.de/~bloch/acng/html/maint.html#auto-cleanup

Basically, you can set up the daily cache cleanup cron to do a full checksum match on your entire cache. This will catch all the bad sizes and any other corruption and clean out those files. I edited /etc/cron.daily/apt-cacher-ng and added the following after the comments:

export ACNGREQ="abortOnErrors=aOe&byPath=bP&byChecksum=bS&truncNow=tN&incomAsDamaged=iad&purgeNow=pN&doExpire=Start+Scan+and%2For+Expiration&calcSize=cs&asNeeded=an"

This is equivalent to clicking all the expiry options on the maintenance page except "Skip header checks..."

Solution 3:

Suggestion 1

sudo rm /var/lib/apt/lists/*gzip*
sudo rm /var/lib/apt/lists/partial/*gzip*
sudo apt-get update

Suggestion 2

sudo rm -f /var/cache/apt/partial/*
sudo rm -f /var/cache/apt/*.deb
sudo apt-get update

Suggestion 3

sudo touch /etc/apt/apt.conf.d/no-cache
sudo nano /etc/apt/apt.conf.d/no-cache

And paste this in:

Acquire::http {No-Cache=True;};

Now try:

sudo apt-get update