Fix "Failed to download metadata for repo" in dnf on Rocky 9
Read the repo ID and URL from the error, clear the cache, then check the failing URL with curl to tell a mirror 404, a missing signature file and a proxy error.
Error: Failed to download metadata for repo '…' is only the last line. The cause is in the Status code: line just above it. The messages below come from public reports, with hostnames changed to example.com. They were not reproduced on Rocky 9.
[1] Read the whole error again. Write down three things: which repo ID failed, which URL, and which status code.
Errors during downloading metadata for repository 'epel':Status code: 404 for http://mirror.example.com/epel/9/Everything/x86_64/repodata/repomd.xml.ascError: Failed to download metadata for repo 'epel': GPG verification is enabled, but GPG signature is not available.[2] Clear the cache and fetch again. clean all removes everything cached; clean metadata removes only repository metadata. The next run downloads fresh metadata.
# dnf clean all# dnf makecache[3] Request the failing URL without dnf and compare the response code with what dnf saw.
$ curl -I http://mirror.example.com/epel/9/Everything/x86_64/repodata/repomd.xmlIf repomd.xml returns 200 but dnf still fails, look at the extra file dnf asks for (such as .asc) or at dnf's own settings, not the URL itself. On 404, read the repo file in step 4.
[4] Sort by what the error says.
| Error | Where to look |
|---|---|
Status code: 404 · repomd.xml | baseurl · mirrorlist · metalink in /etc/yum.repos.d/*.repo |
Status code: 404 · repomd.xml.asc + GPG signature is not available | repo_gpgcheck (step 5) |
Status code: 500 | a proxy or internal mirror in front (note below) |
| timeout | network, DNS, timeout (default 30 s) · retries (default 10) |
By default dnf reads *.repo files under /etc/yum.repos.d and /etc/dnf/dnf.conf. $releasever and $basearch in a URL are replaced with the system's values.
# grep -nE '^\[|baseurl|mirrorlist|metalink' /etc/yum.repos.d/epel.repo[5] Check whether repo_gpgcheck is on globally. That is the EPEL case above: the user had repo_gpgcheck=1 in /etc/dnf/dnf.conf, but EPEL signs packages and not repository metadata, so repomd.xml.asc does not exist.
# grep -rn repo_gpgcheck /etc/dnf/dnf.conf /etc/yum.repos.d/If dnf.conf shows repo_gpgcheck=1, this is your case.
The EPEL maintainer's answer: enable repo_gpgcheck per repo, only for repos with signed metadata, not globally. Remove the line from dnf.conf (or set it to 0) and put repo_gpgcheck=1 under the [ID] of repos that sign their metadata. Setting it to 0 globally, as the reporter did, clears the error but turns off metadata verification for every repo.
[6] While you look for the cause, leave out only the broken repo and carry on.
# dnf --disablerepo=epel updateskip_if_unavailable defaults to False. With True, dnf disables any repo it cannot synchronize and continues. It hides outages, so use it as a temporary workaround, not a standing setting.