449

When I check for updates, I get a "Failed To Download Repository Information" error.

This is what comes up under details:

W: Failed to fetch gzip:/var/lib/apt/lists/partial/us.archive.ubuntu.com_ubuntu_dists_natty_main_source_Sources  Hash Sum mismatch, 
E: Some index files failed to download. They have been ignored, or old ones used instead.
Braiam
  • 67,791
  • 32
  • 179
  • 269
Rob
  • 12,820

22 Answers22

542

Just remove all the content of /var/lib/apt/lists directory:

sudo rm -rf /var/lib/apt/lists/*

then run:

sudo apt-get update
sorin
  • 9,888
Lorem
  • 5,719
  • 89
    If you remove all files, you have to download them again. You can just remove the invalid file to make this process faster. – Behrang Jul 28 '13 at 12:51
  • 12
    I remember this happening with Debian, too. The solution was to switch repositories (eg, from us.ubuntu.com to XX.ubuntu.com where XX is your country code) or waiting. The best idea would be to wait a bit and retry later. Removing the lists might fix broken lists, but that's rarely the case. – f.ardelian Jul 31 '13 at 10:58
  • 8
    Old question, but on some distros (Like emdebian), after doing this you'll need to "mkdir /var/lib/apt/lists/partial" (As root, obviously.), or else you cannot "apt-get update" or otherwise use apt. – Archenoth Dec 26 '13 at 03:48
  • @Behrang: No, you'll not need to download them again. Running sudo apt-get update will populate /var/lib/apt/lists again with the repos along with the list of packages they contain. – heemayl Oct 22 '14 at 19:49
  • 8
    @AlyssaGono if it's a folder, you need to run rm with the recursive flag like so: sudo rm -R /var/lib/apt/lists/* however, even doing that didn't work for me. – mchid Dec 11 '14 at 03:33
  • 3
    We need prefix -rf, so it will look like sudo rm -rf /var/lib/apt/lists/* – Askar Feb 06 '15 at 00:45
  • 1
    Worked for me, installing a brand new Ubuntu 12.04 AMD64 VM (because I need PHP 5.3). Thanks! – Steve Hill Apr 29 '15 at 10:08
  • After doing this, in order to solve my problem, I had to change the update server, which in my case was the portuguese. Changed it to the main one and done update and it worked. – Alexey Nov 05 '15 at 10:30
  • 1
    As suggested by Cam/realhu, this can be done in combination with sudo apt-get clean -- that's what worked for me. – MichaelChirico Mar 10 '16 at 14:55
  • 3
    *It is very important to make a note: this sometimes happens when you query a mirror and it's in the middle of updating from the other mirrors. In those cases, you just have to wait* until the syncs are done and try again later. – Thomas Ward Oct 07 '17 at 15:25
  • This worked great for me. It has been weeks that I had E: Failed to fetch store:/var/lib/apt/lists/partial/cm.archive.ubuntu.com_ubuntu_dists_xenial-backports_main_dep11_icons-64x64.tar.gz Hash Sum mismatch after and apt update + apt upgrade – Salathiel Genese May 08 '18 at 11:29
  • This is all so idiosyncratic voodoo – matanox Jun 06 '18 at 19:42
  • I tried this command but still getting Hash Sum error: _E: Failed to fetch http://es-mirrors.evowise.com/ubuntu/dists/bionic-updates/main/binary-amd64/by-hash/SHA256/c309de7299ec2582c77c7f97351db3f48198f579fea7b9af13f284e5621f0630 Hash Sum mismatch _ – Aakash Patel May 26 '19 at 05:10
  • After doing this Ubuntu Software shows only a couple of apps I can install. Also apt install .. gives error because dependencies are not installable – alaster Aug 03 '19 at 15:56
  • I'm wondering if there's some related issues, so I'll share here exactly what I did because I had an extra step: sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status sudo rm -rf /var/lib/apt/lists/* sudo apt-get clean sudo apt-get update -o Acquire::CompressionTypes::Order::=gz – josephdpurcell Dec 01 '19 at 03:23
  • But, after that I still couldn't upgrade. Come to find out I had bad memory. To confirm this, I rebooted the machine and used the bios diagnostic tool. – josephdpurcell Dec 01 '19 at 16:16
  • I also used the command sudo apt-get update -o Acquire::CompressionTypes::Order::=gz before it worked for me (https://bugs.launchpad.net/ubuntu/+source/apt/+bug/1785778) – wordsforthewise Dec 02 '19 at 21:14
  • with a quite similar problem i found the sub-folder 'partial' to have some files there for the dangling repo in question. after deleting only the files for the server in this subfolder all worked nice again. – Alexander Stohr Feb 24 '20 at 10:42
  • just i run sudo apt upgrade and then sudo apt update and the thing were fixed – Clarance Liberiste Ntwari Jul 07 '21 at 06:28
  • This is unbelievably stupid. Can the OS just be instructed to re-download the broken metadata? – tribbloid Jan 08 '23 at 21:46
  • The only thing that worked for me was to switch from 4G connection (Hotspot) to my Wifi! – Raphaël Goisque Feb 25 '24 at 14:52
  • I had to run apt-get update --fix-missing then it worked perfectly. – Dipanshu Chaubey Mar 26 '24 at 10:59
136

This is a known issue, and is exacerbated for clients behind proxy caches. Some large organisations and ISPs (especially in remote parts of the world) have transparent caches of which you may not be aware.

The fundamental issue is that the apt repository format is subject to race conditions when a mirror is updated. This problem particularly affects repositories that change rapidly, such as the development release.

You can track progress on the fix for this in this bug (please mark yourself as "affects me too" in the bug) and this blueprint. But be aware that it is a complex issue and may take more than one release to resolve.

Robie Basak
  • 15,670
124

The easiest way to fix this is:

sudo apt-get clean
sudo apt-get update
realhu
  • 1,699
82

The only solution that worked for me is from unix.stackexchange.

It happens because there's a known bug it apt, and the solution is to update with a different compression method, so the files load correctly and the checksum succeeds.

Give this a try:

sudo rm -rf /var/lib/apt/lists/partial
sudo apt-get update -o Acquire::CompressionTypes::Order::=gz

(thanks @brook_hong from the comments for the rm part)

Amir Uval
  • 1,143
  • 9
  • 9
  • 12
    This is the only solution here that worked for me. Thanks. – Cerin Jun 21 '16 at 17:53
  • 3
    It worked for me too. Note that you don't have to always run this command. Just run it once, and then you can run "apt-get update" without error. – dalf Jul 06 '16 at 01:35
  • 1
    Before try with the option, we must clean the partial folder -- sudo rm -rf /var/lib/apt/lists/partial. I wrote an article for why.

    https://brookhong.github.io/2016/10/10/troubleshoot-hash-sum-mismatch-of-apt-get.html

    – brook hong Oct 10 '16 at 10:17
  • 2
    I tried using the generic solution from various forums but this works out of the box. Thank you. – khwilo May 26 '18 at 14:41
  • 2
    Worked for me on Ubuntu 16.04/linux mint – David Okwii Jun 13 '18 at 17:09
  • 4
    This is the only solution worked for me, am using Ubuntu 16.04 – Sunny Shukla Sep 22 '18 at 08:17
  • I upgraded ubuntu 16 to 18 and received hash mismatch error for some i386 packages. I'm trying to install steam. Only this method worked for me. Can you explain this command? What makes it? – kodmanyagha Jan 04 '19 at 00:48
  • I did explain in my answer. The command changes the compression method. – Amir Uval Jan 04 '19 at 08:07
  • @AmirUval what is the default compression method? – vikarjramun Jul 20 '19 at 15:50
  • @vikarjramun If you're here - then your default is probably LZMA (.xz) compression, which has this problem – Amir Uval Jul 23 '19 at 11:47
  • @AmirUval Yes, I had the same problem as the question, and your solution fixed it. Would it be in my best interest to revert to xzip using sudo apt update -o Acquire::CompressionTypes::Order::=xz? I know xzip has a better compression ratio but how marginal is it for deb packages? (19.04 if it matters) – vikarjramun Jul 23 '19 at 16:13
  • xz is better, but I wouldn't spend too much time optimising something that is good enough. – Amir Uval Jul 24 '19 at 07:00
  • @AmirUval I'm back again, this time with the exact same problem :). I tried switching back to xz, and back to gz again, but neither work. What other encodings can I try? Also, what is a good permanent solution to this problem? – vikarjramun Sep 22 '19 at 23:12
  • @vikarjramun I cannot reproduce the problem you have. If I'll see the problem again I will post an update. – Amir Uval Sep 23 '19 at 06:39
  • Worked for me on Ubuntu 18.04. I don't understand why would the default apt configuration cause this. This is madness, I lost 1h of valuable work time because of this. – Spirit Mar 25 '20 at 08:26
  • This worked for me! – Vishal Kamlapure Dec 01 '20 at 07:14
  • 1
    It should be accepted one – Malavan Aug 19 '21 at 08:01
56

I still had the problem after removing the directories and doing sudo apt-get update.
Only the following step solved my problem:

sudo sed -i -re 's/\w+\.archive\.ubuntu\.com/archive.ubuntu.com/g' /etc/apt/sources.list

I don't know if this is the right way of fixing it...
I've found the solution here.

m13r
  • 667
  • 5
  • 8
  • 3
    This was the only solution that works for me with Ubuntu 20.04.2 LTS. Thanks! – august0490 Jul 23 '21 at 14:53
  • I kept getting this problem with "hirsute-updates/universe amd64 DEP-11 Metadata" on Ubuntu 21.04, tried all the other answer and nothing worked... this solved it! Thanks @m13r! – João Ciocca Aug 03 '21 at 15:25
25

This can happen when your mirror is not up to date or serving errors from being overloaded. You can either wait a while and try again, or switch to another mirror:

Jorge Castro
  • 71,754
  • 2
    Why does a server not being up to date, or being overloaded, cause a file with the correct name to successfully download (in the sense that the connection doesn't terminate until all the bytes are sent and received), but be corrupted? (I'm not asserting that doesn't happen, I'm just hoping you might be able to explain why it does.) – Eliah Kagan Aug 13 '12 at 21:30
  • 4
    @EliahKagan The problem normally is not that the file itself is corrupted, but that there is a (I am simplifying but not too much) data file and an index file containing the hash (fingerprint) of the data file. When the repositories are updated (happens every hour) on the server one file after the other gets updated. Now it can happen that your client (apt-get or similar) accesses the server when the data file has been updated but the index file has not been updated (or vice versa), yet. Then the hash doesn't match the data file and the client (falsely) assumes that the data file is corrupted. – Patrick Häcker Apr 14 '14 at 06:49
  • 1
    Changing the mirror worked for me when none of the above answers did. – mango Mar 25 '16 at 16:16
16

If you're behind a proxy, then create a file named 99fixbadproxy in /etc/apt/apt.conf.d/:

sudo gedit /etc/apt/apt.conf.d/99fixbadproxy

Paste this into 99fixbadproxy and save it:

Acquire::http::Pipeline-Depth 0;
Acquire::http::No-Cache true;
Acquire::BrokenProxy    true;

Now run the update command:

sudo apt-get update
Musaffa
  • 323
  • 3
  • 5
10

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.

Trey
  • 202
  • 2
  • 7
5

The following commands may solve your issue.

sudo rm -R /var/lib/apt/lists/partial/*

and then

sudo apt-get update && sudo apt-get upgrade

it will solve your problem. I also faced the same problem but the above commands solved the problem for me. So give them a try.

Solution reference

4

I had the exact same problem and all solutions provided using the terminal did not help.

For me, it was by going into:

Settings → Software & Updates → Ubuntu Software: Download from: Change Local to Main Server.

It starts reloading the repos and updating. When I enter:

sudo apt-get update

After that, there was no problem at all. I'm using Ubuntu 14.04.4 LTS.

galoget
  • 2,963
habibun
  • 631
  • After changing Updates Download server to Main restart the computer and then run sudo apt-get update or sudo apt update . This fixed the issue in Ubuntu 20.04. – Eric kioko May 28 '20 at 13:13
2

If you're running Linux inside VirtualBox on Windows and have Hyper-V (or WSL 2, which uses Hyper-V) enabled at the same time, you're in for a world of pain. This being one symptom. VirtualBox 6.1 says on the tin that it supports Hyper-V but it just isn't true (as of 2020-08-25 windows v2040 at least). Disable Hyper-V and you're golden. From another answer:

In an elevated Command Prompt write this :

To disable:

bcdedit /set hypervisorlaunchtype off

To enable:

bcdedit /set hypervisorlaunchtype auto 

restart to take effect

2

I don't know that it's proper solution or not, but I did the following and the error message's gone:

After typing sudo apt-get update in terminal, it gives me the names of some packages which cause the error then I did the following:

Update manager(software update) → Setting → Configure Software Sources → Other software[tab] → Uncheck the packages

After pressing the "close" bottom, update manager started to check for update automatically again and I saw this message:"the software on this computer is up to date. Last checked 2 seconds ago."

Kubuntu 12.04

user.dz
  • 48,105
Hassan.J.
  • 21
  • 1
  • This worked for me, and no other solution posted here worked. Except I don't have the Ubuntu UI (running command-line only under WSL), So instead, for each package <pkg> where the error occurred, I ran `sudo apt-get install '. I am on Ubuntu 16.04. – Yitz Feb 20 '18 at 13:29
  • If I understand correctly, this just stops the updates for that specific software altogether. This is hardly a solution, is it? – thymaro May 01 '20 at 05:43
2

I had a similar problem and solved it by opening theh application "Software & Updates" and, in "Ubuntu Software" tab, changing the value of "Download from" (in that drop-down list, try to select, for example, Main Server if it was not like that).

1

I had the exact same problem and all solutions provided using the terminal did not help.

For me, it was by going into:

Settings → Software & Updates → Other software: Uncheck all the boxes and press close.

It starts reloading the repos and updating. When I enter:

sudo apt-get update

After that, there was no problem at all. I'm using Ubuntu 13.10.

Mateo
  • 8,104
  • This does work yet it effectively blinds the machine from being able to install packages not part of the core build (until those checkboxes are re-activated later) ... yet necessary at times just to achieve an error free apt-get update which enables install of targeted packages – Scott Stensland Apr 06 '16 at 15:39
1

As follow @robie-basak, I used apt-cacher-ng as mirror caching. So I Remove the proxy and the problem solved.

I remove the proxy in file /etc/apt/apt.conf.d/01proxy:

#Acquire::http::Proxy "http://xxx.xx.xx.xx:4321";

Then need to:

sudo rm -rf /var/lib/apt/lists/*
sudo aptitude update
sudo aptitude upgrade
shgnInc
  • 4,003
1

I had just recently install Ubuntu 17.10 and was getting the same error of Hash Sum Mismatch for a some repository.I went to Software and Checked Source as shown below and there were no problems further for downloading repository from the terminal.

My Software and Update Section

0

This can happen if you're running a router with parental controls, and havent put your raspberry pi into an "unmanaged" list. For me, I could see the url was redirecting to a circle domain, managed by the router.

So I just added my pi to the unmanaged list, and it worked fine.

brad parks
  • 2,427
0

Nothing worked for me. After trying and the suggested solutions, finally, I had downloaded the broken packages manually, copied them into /var/cache/apt/archives and removed the broken packages from /var/cache/apt/archives/partial.

0

I faced the same problem in my Ubuntu 18.04, below is my practical experience:

  1. Remove the proxy in /etc/apt/apt.conf
  2. Change to official apt sources.list /etc/apt/sources.list
  3. Run sudo rm -rf /var/lib/apt/lists/*
  4. Clean packages sudo apt autoremove -y && sudo apt autoclean -y
  5. Update and Upgrade. sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y

Done!

Max Xu
  • 687
0

This happened for me on Ubuntu 16.04, and none of the top voted solutions worked. The solution was upgrading packages:

sudo apt-get update    # this will fail
sudo apt-get upgrade
sudo apt-get update    # this will succeed

Not sure if cleaning old lists (sudo rm -rf /var/lib/apt/lists/* and/or sudo apt-get clean) helped or not! Use them if necessary.

Moha Dehghan
  • 231
  • 2
  • 7
0

20190112 #Errors #apt #Fix #Updates Failed to fetch ... Hash Sum mismatch

  1. Run apt-get and find out what key words to search for in /etc/apt:
    • $ sudo apt-get -y update
    • ...
    • Err:77 http://au.archive.ubuntu.com/ubuntu xenial-updates/multiverse DEP-11 64x64 Icons
    • Hash Sum mismatch
    • ...
    • In this case, the keyword is "DEP-11"
  2. Search the /etc/apt tree for the keyword(s):
    • $ sudo find /etc/apt -type f -exec egrep -in "DEP-11" "{}" /dev/null ";"
    • /apt.conf.d/50appstream:1:## This file is provided by appstreamcli(1) to download DEP-11
    • /apt.conf.d/50appstream:6: deb::DEP-11  {
    • /apt.conf.d/50appstream:9: Description "$(RELEASE)/$(COMPONENT) $(NATIVE_ARCHITECTURE) DEP-11 Metadata";
    • /apt.conf.d/50appstream:15: # Normal-sized icons for GUI components described in the DEP-11
    • /apt.conf.d/50appstream:17: deb::DEP-11-icons {
    • /apt.conf.d/50appstream:20: Description "$(RELEASE)/$(COMPONENT) DEP-11 64x64 Icons";
    • /apt.conf.d/50appstream:27: # the DEP-11 YAML metadata.
    • /apt.conf.d/50appstream:28: deb::DEP-11-icons-hidpi {
    • /apt.conf.d/50appstream:31: Description "$(RELEASE)/$(COMPONENT) DEP-11 128x128 Icons";
  3. Having found the offending list, move it somewhere just in case this doesn't work:

    sudo mv -f /apt.conf.d/50appstream /tmp  
    
  4. Clean up /var/lib/apt:

    sudo apt-get -y clean  
    sudo rm -rf /var/lib/apt/lists/*  
    sudo find /var/lib/apt -type d -name "partial" -exec rm -rf "{}" ";"  
    
  5. Try to update now, it should work now:

    sudo apt-get -y update  
    
karel
  • 114,770
0

I have resolved all the packages not being installed by running this command:

sudo apt-get install PACKAGENAME

For each of the packages. They are now installed and the "Hash Sum mismatch" error has gone.

galoget
  • 2,963
BiggJJ
  • 1,249
  • 9
  • 23