How to fix “Failed to synchronize cache for repo appstream”

Updated on March 4, 2022

Recently I had explored upgrading CentOS 7 to CentOS 8 and during the process, I encountered the error: Failed to synchronize cache for repo ‘appstream’. Below is the complete error:

Failed to synchronize cache for repo 'baseos', ignoring this repo.
Failed to synchronize cache for repo 'appstream', ignoring this repo.

Output from the /var/log/dnf.log for more DEBUG information:

2022-02-15T10:09:08Z DEBUG repo: downloading from remote: appstream
2022-02-15T10:09:08Z DEBUG Cannot download 'http://mirror.centos.org/centos/8/AppStream/x86_64/os/': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried.
2022-02-15T10:09:08Z DEBUG repo: downloading from remote: extras
2022-02-15T10:09:08Z DEBUG not found other for: CentOS Linux 8 - Extras
2022-02-15T10:09:08Z DEBUG not found modules for: CentOS Linux 8 - Extras
2022-02-15T10:09:08Z DEBUG not found deltainfo for: CentOS Linux 8 - Extras
2022-02-15T10:09:08Z DEBUG not found updateinfo for: CentOS Linux 8 - Extras
2022-02-15T10:09:08Z DEBUG extras: using metadata from Fri 10 Dec 2021 06:26:25 PM IST.
2022-02-15T10:09:08Z WARNING Failed to synchronize cache for repo 'baseos', ignoring this repo.
2022-02-15T10:09:08Z WARNING Failed to synchronize cache for repo 'appstream', ignoring this repo.

Looking at the error message, I thought the issue might be because of the internet connection. However, the internet connection and DNS worked just fine as shown below.

[root@upgrade-centos log]# ping google.com
PING google.com (172.217.166.206) 56(84) bytes of data.
64 bytes from del03s13-in-f14.1e100.net (172.217.166.206): icmp_seq=1 ttl=115 time=44.10 ms
^C
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 44.971/44.971/44.971/0.000 ms

So how did I fix the issue? Here it is.

How to fix Failed to synchronize cache for repo appstream

There could be multiple reasons for this issue. The most common ones are:

  • Incorrect date and time settings
  • Old dnf cache available or expired
  • CentOS baseURL

How to fix Incorrect date and time settings

The timedatectlcommand is a new utility tool in CentOS 7/8. It is a replacement for old traditional date command used in sysvinit daemon-based Linux distributions.

Find the current date and time of your system. Make sure it is correct with the proper time zone.

[root@upgrade-centos ~]# timedatectl
Local time: Tue 2022-02-15 11:24:25 UTC
Universal time: Tue 2022-02-15 11:24:25 UTC
RTC time: Tue 2022-02-15 11:24:25
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: active
RTC in local TZ: no

Set to your timezone

[root@upgrade-centos ~]# timedatectl set-timezone "Asia/Kolkata"

[root@upgrade-centos ~]# date
Tue Feb 15 16:58:57 IST 2022

How to clear Old/expired dnf cache

Here is an article to clean each kind of cache. To clean all of it, run the below command:

[root@upgrade-centos ~]# dnf clean all
[root@upgrade-centos ~]# rm -rf /var/cache/dnf

How to change CentOS baseURL from mirror.centos.org to vault.centos.org

CentOS Linux 8 had reached the End Of Life (EOL) on December 31st, 2021. It means that CentOS 8 will no longer receive development resources from the official CentOS project. After Dec 31st, 2021, if you need to update your CentOS, you need to change the mirrors to vault.centos.org where they will be archived permanently. Alternatively, you may want to upgrade to CentOS Stream or migrate from CentOS to Rocky Linux.

Go to the /etc/yum.repos.d/ directory.

[root@autocontroller ~]# cd /etc/yum.repos.d/

Run the below commands

[root@autocontroller ~]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@autocontroller ~]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

Now run  dnf update

[root@autocontroller ~]# dnf update

That’s it!

Was this article helpful?

Related Articles

Comments Leave a Comment

  1. Nice! it works as long as i dont do dnf update!
    that actually broke my last system so i run the two “sed” commands and just leave it at that

  2. Thank you, it helped me update my system (installed in late October 2021, so just a few months before CentOS 8 went EOL:ed). People joke about which year Linux Desktop will become reality, but I find that Linux Server is complicated as it is with these upgrades, changed paths and whats not.

  3. Now I get an error saying “Cannot find a valid baseurl for repo: AppStream”
    anybody else with the same issue?

  4. thanks man ! it’s working … your content is appreciated

Leave a Comment