CentOS 8 - yum/dnf error: Failed to download metadata for repo [closed]
Asked Answered
K

10

32

On my CentOS 8 server, many dnf and yum commands fail with this error:

Failed to download metadata for repo

This seems to apply only to repositories involving https connections, e.g.:

/etc/yum.repos.d $ cat epel-modular.repo
[epel-modular]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch/pub/epel/$releasever/Modular/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-modular-$releasever&arch=$basearch&infra=$infra&content=$contentdir
...

I have used wget to test connectivity to these sites and it is successful, e.g. wget https://mirrors.fedoraproject.org succeeds.

However, various dnf or yum commands fail:

$ dnf provides /bin/ls
Extra Packages for Enterprise Linux Modular 8 - x86_64     0.0  B/s |   0  B     00:00
Failed to download metadata for repo 'epel-modular'
Error: Failed to download metadata for repo 'epel-modular'

# dnf update --refresh
CentOS-8 - AppStream                                        20 kB/s | 4.3 kB     00:00
CentOS-8 - Base                                             19 kB/s | 3.8 kB     00:00
CentOS-8 - Extras                                          7.4 kB/s | 1.5 kB     00:00
CentOS-8 - PowerTools                                       20 kB/s | 4.3 kB     00:00
Remi's Modular repository for Enterprise Linux 8 - x86_64  4.1 kB/s | 3.5 kB     00:00
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 3.6 kB/s | 3.0 kB     00:00
Wazuh repository                                           0.0  B/s |   0  B     00:00
Failed to download metadata for repo 'wazuh_repo'
Error: Failed to download metadata for repo 'wazuh_repo'

How do I resolve this problem?

Kildare answered 30/1, 2020 at 20:0 Comment(2)
You can have problems connecting to a repo for all kinds of reasons, so it is always good to use the dnf update -v (v for verbose) to get as much information as possible.Outdate
While I agree this is an off-topic question because it is the first hit in search engines, here is a possible solution: (I am aware I shouldn't answer this, but editing would be the bigger evil): Check /etc/yum/vars/releasever if it contains a minor version edit: sed -i 's/$releasever/8/g' /etc/yum.repos.d/epel*.repo to reflect only the major version. Taken from access.redhat.com/discussions/5473561Tiein
I
47

In my case

sudo rm -r /var/cache/dnf 

solved my problem.

Source: https://access.redhat.com/discussions/4222851

Iterative answered 7/2, 2020 at 5:2 Comment(3)
You could improve this answer by explaining why removing this folder resolves the issue.Cotoneaster
Works for me after switching to CentOS 8 stream.Euthenics
Did not work for me, at least breaking regarding the Updates repo on an old version of Fedora, possibly with mixed repo responses based on the archived nature of these release versions, from 34 to 36, when around 39 is available currently. Thought the other answer was helping clear more metadata caches on my system to fix the links now, but still not working.Cashman
L
12

I was getting the same error with the Centos8 build inside of a docker container. Fixed by running the below:

# Do on build
RUN dnf clean all && rm -r /var/cache/dnf  && dnf upgrade -y && dnf update -y 

Error before (i was running yum update and not dnf):

Step 4/5 : RUN yum clean all && yum update -y && echo hostname -a
 ---> Running in 10d319da361d
0 files removed
CentOS-8 - AppStream                            0.0  B/s |   0  B     00:05    
Failed to download metadata for repo 'AppStream'
Error: Failed to download metadata for repo 'AppStream'

Success after:

 ---> 0b96049ee5eb
Step 4/5 : RUN dnf clean all && rm -r /var/cache/dnf  && dnf upgrade -y && dnf update -y & echo hostname
 ---> Running in f928c6da6cb0
hostname
Removing intermediate
Lied answered 8/3, 2020 at 8:16 Comment(5)
dnf upgrade leads to the same errorDumbfound
running the whole string of commands or just that one? You may have a separate root cause than i had, sorry 😰Lied
i don't understand why, but this line saved my life dnf clean all && rm -r /var/cache/dnf && dnf upgrade -y && dnf update -yElba
Thought this was helping me to clear more metadata caches from my system and fix the repo links than the other answer, but still not working regarding the Updates repo on an old version of Fedora, possibly with mixed repo responses based on the archived nature of these release versions, from 34 to 36, when around 39 is available currently.Cashman
Some combination of these commands may have helped. I also had an OS release version with data filed in the archive section (34), but the target version (36) only partially existed between there and the normal section concerning the normal and updates repositories, or 1 was missing, so I also had to choose a more completely supported version (37), clean anything, set my repo files back to using the normal link, have a key issue, could not find where to download it, gpgcheck=1 did not help, also used --nogpgcheck, then waited a long time 1-2 hours and finally worked O_o.Cashman
L
9

I just faced this problem so I thought I'd add what fixed it for me since the resolution was pretty simple. For me, I was overlooking the fact that whenever I changed my hostname, it was wiping out everything in /etc/resolv.conf so I:

  1. nano -w /etc/resolv.conf **
  2. added the following lines:

    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
  3. Test it (e.g. yum update -y)

**note: I used nano in example, simply swap the nano portion for your own text editor of choice

Lean answered 29/4, 2020 at 22:41 Comment(0)
K
3

If it does not work, check your Internet connection. This error appeared on my CentOS 8 installation, and the problem was that the Internet connection wasn't correctly configured.

Kaenel answered 10/2, 2020 at 13:14 Comment(1)
You were right, for people who has the same problem, add this line to your /etc/sysconfig/network-scripts/ifcfg-eth0 file: ONBOOT=yes. Original answer here.Ictinus
W
2

Just add the following (DNS server) to /etc/resolv.conf file:

nameserver 9.9.9.9

Will fix the issue :)

Wilcox answered 4/4, 2020 at 12:21 Comment(3)
Can you explain why this fixes the issue? Is this a private DNS server, and if so, whose control is it under?Bluebill
What is this supposed to do?Warfield
Dear @Yazan Yahya, you save my day. Thank you very much.Pelt
K
1

You may not realize it, but yum and dnf require SSL certificates when communicating via secure HTTP (aka HTTPS). Have you checked the certificates under /etc/pki/tls/certs? There should be at least two, for example:

/etc/pki/tls/certs# ls -l
total 4
lrwxrwxrwx 1 root root   49 Jan 30 12:48 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx 1 root root   55 Dec 11 13:19 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt

If these links are missing you may be able to simply restore them. Otherwise, the files are part of the ca-certificates package. You can obtain them from another server running your operating system via yumdownloader then restore your certificates from the resulting RPM file using yum --nogpgcheck localinstall <RPM file>.

Kildare answered 30/1, 2020 at 20:0 Comment(1)
you can download the package via wget, curlor any browserHydrophobic
A
0

I was facing this issue when I tried to run

yum update -y

from a docker container. I changed the version from centos:8 to centos:7 and it solved the issue for me.

Architectonic answered 5/3, 2020 at 6:52 Comment(1)
In build/Dockerfile is the "where" in my caseTieratierce
O
0

I had the same error after I was messing around with SD adapter to microSD card. Edit /etc/fstab to remove SD line solved the issue for me.

Oralla answered 27/3, 2020 at 10:47 Comment(0)
G
0

I will confirm I recently had this issue and what fixed it for me was a change in the DNS servers. I had a static IP set but DNS was automatic, I had to reconfigure DNS to use my gateway and dc. This is working now.

Gardant answered 23/4, 2020 at 14:15 Comment(0)
O
0

My issue was that the interface wasn't up after a fresh vm install. Ran ifconfig to find my interface name and then ifup eXXX to get a dhcp ip address.

Also don't forget to change ONBOOT=no to ONBOOT=yes in /etc/sysconfig/network-scripts/ifcfg-eXXX so it comes up during next boot.

Obovoid answered 1/5, 2020 at 23:51 Comment(1)
In my case I had a static IP Address configured & was missing the DNS entry in that configuration. Following this guide to properly assigning a static IP on CentOS 8 fixed my issue: howtoforge.com/how-to-configure-a-static-ip-address-on-centos-8Volcanism

© 2022 - 2024 — McMap. All rights reserved.