Visual Studio Code – Fix Hash Sum Mismatch

Yesterday, I did $ sudo apt update and I ended up getting the following error –

Err:25 http://packages.microsoft.com/repos/vscode stable/main amd64 Packages

Hash Sum mismatch

To be honest, I had no idea what does this error even stands for, so I searched for ubuntu apt-update hash sum mismatch fix on google, and got the following results –

One of the users wrote that the easiest fix would be –

$ sudo apt clean
$ sudo apt update

Another fix, according to a user, was to remove the contents of

/var/lib/apt/lists

and run

sudo apt update

A comment on that answer suggested –

If you remove all files, you have to download them again. You can just remove the invalid file to make this process faster.

Part 1

Now, I had two options to fix the issue, but for some reasons, I didn’t want to remove the contents of

/var/lib/apt/lists

so I started with –

sudo apt clean
sudo apt autoclean
sudo apt update

Unfortunately, the solution didn’t work. I was still getting the hash sum mismatch error

Part 2

Removing the contents of /var/lib/apt/lists

Since the source of the problem was Visual Studio Code, it was completely unnecessary to remove all the files. So, I just had to delete the files which were related to vscode –

1 – Search for files

cd /var/lib/apt/lists
ls | grep vs
packages.microsoft.com_repos_vscode_dists_stable_InRelease
packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages

2 – Enter superuser mode and delete files

sudo su 
cd /var/lib/apt/lists
rm packages.microsoft.com_repos_vscode_dists_stable_InRelease
rm packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages

3 – Clean, remove and update

sudo apt clean && sudo apt autoclean && sudo apt remove && 
sudo apt autoremove && sudo apt update

ISSUE

The problem didn’t disappear.

It was still getting the same error while updating. Only this time, I read the error carefully.

Part 3

This part is all about hit and trial, and trusting my instincts alongside!

Failed to fetch http://packages.microsoft.com/repos/vscode/dists/stable/main/binary-amd64/Packages.bz2

The above error made me check if Packages.bz2 file exists in /var/lib/apt/lists. So, I checked –

ls /var/lib/apt/lists | grep Packages.bz2

Result – Nothing. Packages.bz2 was missing! Good News?

My initial thought – Add Packages.bz2 to /var/lib/apt/lists and run sudo apt update.

Problem – I had already deleted the two files. –

packages.microsoft.com_repos_vscode_dists_stable_InRelease
packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages

How to get those files back?

The files available in /var/lib/apt/lists are in the form of site.com_foo_bar_buzz. Now, if you replace _ with /, you’ll get –

site.com/foo/bar/buzz

So,

packages.microsoft.com_repos_vscode_dists_stable_InRelease

will become –

packages.microsoft.com/repos/vscode/dists/stable/InRelease

Since two of the files related to VSCode were already gone, I had to download them and put them back to their place. Kudos to history.

history | grep packages.microsoft

I also needed the Packages.bz2 file, so I grabbed the downloadable link from the error message.

http://packages.microsoft.com/repos/vscode/dists/stable/InRelease
http://packages.microsoft.com/repos/vscode/dists/stable/main_binary-amd64_Packages
http://packages.microsoft.com/repos/vscode/dists/stable/main/binary-amd64/Packages.bz2

  • Step 1 – Download the files.
  • Step 2 – Rename files. The name of the files should be similar to the url they were obtained form, except / will be replaced by _. InRelease, Packages, and Packages.bz2 will become –
packages.microsoft.com_repos_vscode_dists_stable_InRelease
packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages
packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages.bz2

Now, move those files to /var/lib/apt/lists

sudo su

mv packages.microsoft.com_repos_vscode_dists_stable_InRelease /var/lib/apt/lists
mv packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages /var/lib/apt/lists
mv packages.microsoft.com_repos_vscode_dists_stable_main_binary-amd64_Packages.bz2 /var/lib/apt/lists
  • You can move them all together. It doesn’t matter.

Run sudo apt update.

This fixed the whole Hash Sum Mismatch error for me!

I had no idea if it would work or not. I attempted to solve a problem, and everything went fine.

Links

 

This article was originally posted here!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s