Home FAQ Fix “W: Some index files failed to download.” Error In Ubuntu
Fix "W: Some index files failed to download." Error In Ubuntu

Fix “W: Some index files failed to download.” Error In Ubuntu

By sk
375 Views

It seems one of the Ubuntu mirror is down today and I couldn't install any new package in my Ubuntu 20.04 LTS server. When I try to update software source lists, I get this error - "W: Some index files failed to download. They have been ignored, or old ones used instead." I tried updating repository lists couple times, rebooted the server, but still I get the same error. I checked the Internet connection, it is working just fine!

I ran the following command to update my Ubuntu server:

$ sudo apt update

And I encountered with this error:

Err:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
  Could not connect to in.archive.ubuntu.com:80 (2403:8940:ffff::f), connection timed out Could not connect to in.archive.ubuntu.com:80 (103.97.84.254), connection timed out
Err:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
  Unable to connect to in.archive.ubuntu.com:http:
Err:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
  Unable to connect to in.archive.ubuntu.com:http:
Err:4 http://in.archive.ubuntu.com/ubuntu focal-security InRelease
  Unable to connect to in.archive.ubuntu.com:http:
Reading package lists... Done                           
Building dependency tree       
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/focal/InRelease  Could not connect to in.archive.ubuntu.com:80 (2403:8940:ffff::f), connection timed out Could not connect to in.archive.ubuntu.com:80 (103.97.84.254), connection timed out
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease  Unable to connect to in.archive.ubuntu.com:http:
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease  Unable to connect to in.archive.ubuntu.com:http:
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/focal-security/InRelease  Unable to connect to in.archive.ubuntu.com:http:
W: Some index files failed to download. They have been ignored, or old ones used instead.

Some index files failed to download. They have been ignored, or old ones used instead.

As you can see in the above output, one of the mirror is down and we had to either disable or replace it with a working one to fix this error.

Fix "W: Some index files failed to download." Error In Ubuntu

This error will usually solve itself once the Ubuntu mirror comes back online. Just in case the mirror is down for several hours, follow any one of the methods given below to fix it.

Method 1 - Find best Ubuntu APT repository mirror

The recommended way to fix this issue is to find a best working Apt archive mirror for your location and update your /etc/apt/sources.list file accordingly. The following guide provides all possible ways to find best Ubuntu APT repository mirror based on download speed. The mirrors may not always be the closest to your location but offers a best possible download rate and update status.

Method 2 - Switch back to original mirror

Before modifying the source lists, it is highly recommended to backup them first:

$ sudo mv /etc/apt/sources.list{,.backup}
$ sudo mv /etc/apt/sources.list.d{,.backup}

Ubuntu has a sample source lists in /usr/share/doc/apt/examples/sources.list file. Let us take look at the contents of this file:

$ cat /usr/share/doc/apt/examples/sources.list

Sample output:

# See sources.list(5) manpage for more information
# Remember that CD-ROMs, DVDs and such are managed through the apt-cdrom tool.
deb http://us.archive.ubuntu.com/ubuntu focal main restricted
deb-src http://us.archive.ubuntu.com/ubuntu focal main restricted

deb http://security.ubuntu.com/ubuntu focal-security main restricted
deb-src http://security.ubuntu.com/ubuntu focal-security main restricted

deb http://us.archive.ubuntu.com/ubuntu focal-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu focal-updates main restricted

Now create a new source lists from the sample file like below:

$ sudo mkdir /etc/apt/sources.list.d
$ sudo cp /usr/share/doc/apt/examples/sources.list /etc/apt/sources.list
$ sudo apt update

This will restore all mirrors to main server, usually the mirrors in US.

Add additional repositories

We have enabled the [Main] repository. This repository contains Canonical-supported free and open-source software.

If you want to install community-supported free and open source packages, non-free packages, software that is not available under a completely free license etc., you need to enable the following repositories:

  • Restricted - Proprietary drivers for devices.
  • Multiverse - Software restricted by copyright or legal issues.
  • Universe - Community-maintained free and open-source software.

To enable these repositories, run:

$ sudo add-apt-repository restricted
$ sudo add-apt-repository multiverse
$ sudo add-apt-repository universe
$ sudo apt update

You can check all enabled repositories like below:

$ grep ^deb /etc/apt/sources.list
Disable source repositories

If you look into that new sources.list file, the source repositories have also been enabled. The lines start with "deb-src" indicates source repositories which contains the source packages. This is useful for developers. If you are a regular user, you don't them.

To disable the source repositories, open the /etc/apt/sources.list file and simply put a hash symbol (#) in front of the line starts with deb-src. After commenting out, the line should look like below:

#deb-src http://us.archive.ubuntu.com/ubuntu focal-updates main restricted
[...]

Now update the source list and see if it is fixed.

If you live outside of US, the main mirrors might probably be slower. In that case, you can switch to the nearest mirror location as described in the following section.

Method 3 - Choose nearest mirror from official Ubuntu mirrors

There are hundreds of community-driven mirrors available all over the world. These mirrors provide repositories and archives of all software for your Ubuntu distribution. Navigate to the following link to view all available mirrors:

From this link, choose your country or any nearest location of your choice. For example, I choose a mirror in India.

Official Archive Mirrors for Ubuntu

In the next screen, select your Ubuntu distribution version. Now you will get sources.list entries as shown in the below picture.

Get sources.list entries for Ubuntu

Copy these lines and add them in your /etc/apt/sources.list file. If you don't want the source repository, simply comment it out.

Add additional repositories

We only added the [Main] repository. To enable other useful repositories such as restricted, security, updates etc., run:

$ sudo add-apt-repository restricted
$ sudo add-apt-repository multiverse
$ sudo add-apt-repository universe
$ sudo apt update

Method 4 - Copy source lists from another working system

If you already have another machine that runs the same Ubuntu version, just copy the contents of sources.list file and use them in your system. This is the simplest and easiest way.

If the additional repositories, such as Restricted, Multiverse and Universe, aren't enabled yet, do:

$ sudo add-apt-repository restricted
$ sudo add-apt-repository multiverse
$ sudo add-apt-repository universe
$ sudo apt update

Bonus - Install updates and security patches automatically

This is optional. Ubuntu releases security updates and patches periodically. We should install them to secure our system. To automatically install these updates and patches, you need to install "unattended-upgrade" package and configure it as described in the following link.

Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More