Linux  ·  medium  ·  Core system faults

"Failed to synchronize cache for repo" / "Cannot prepare internal mirrorlist"

dnf or yum could not reach the repository metadata. The curl error number in the message identifies the cause precisely.

What you see

Any dnf operation fails at the metadata stage. Curl error 6 is DNS, 7 is connection refused, 60 is certificate validation, 28 is timeout.

What is actually wrong

DNS, a proxy, an expired CA bundle, a clock that is wrong enough to invalidate certificates, or — on CentOS 7 and CentOS 8 — mirrors that no longer exist because the distribution went end of life.

Codes and articles

Failed to synchronize cache for repoCannot prepare internal mirrorlistCurl error (6)Curl error (60)No URLs in mirrorlist

Fixes (2)

Work through the curl error
Shell as root30 minuteslow riskreversible

A supported distribution whose repositories should still exist.

  1. Get the full error including the curl number.

    Shell
    sudo dnf clean all && sudo dnf makecache 2>&1 | tail -20
  2. Curl error 6 — DNS. Test resolution.

    Shell
    getent hosts mirrors.rockylinux.orgcat /etc/resolv.conf
  3. Curl error 60 — certificate. Check the clock first, then the CA bundle.

    Shell
    timedatectlsudo update-ca-trust extract

    A clock wrong by more than the certificate's validity window makes every HTTPS mirror fail validation, and the error says nothing about time.

  4. Curl error 7 or 28 — connectivity or proxy. Set the proxy in dnf's own config if one is needed.

    Shell
    grep -i proxy /etc/dnf/dnf.conf /etc/yum.conf 2>/dev/nullcurl -sS -o /dev/null -w '%{http_code}\n' https://mirrors.rockylinux.org
  5. Test one repository at a time to find which is broken.

    Shell
    sudo dnf repolist --allsudo dnf makecache --repo=baseos
  6. Disable a repository that is genuinely gone rather than letting it block everything.

    Shell
    sudo dnf config-manager --set-disabled brokenrepo
Confirm it workedMetadata downloads.
Shell
sudo dnf makecache && sudo dnf repolist
If you need to undo itRe-enable a repository with dnf config-manager --set-enabled.
Repoint a CentOS 7 or 8 system at the vault
Shell as root30 minutesmedium riskreversible

CentOS 7 or CentOS 8. The mirrorlist service no longer answers for these, so this is not a network fault — the mirrors are gone.

  1. Confirm the version.

    Shell
    cat /etc/centos-release
  2. Back up the repo files before editing them.

    Shell
    sudo cp -a /etc/yum.repos.d /etc/yum.repos.d.bak
  3. Comment out the mirrorlist lines and point baseurl at vault.centos.org.

    Shell
    sudo sed -i -e 's/^mirrorlist=/#mirrorlist=/' -e 's|^#\?baseurl=http://mirror.centos.org|baseurl=https://vault.centos.org|' /etc/yum.repos.d/CentOS-*.repo

    The vault holds the final released packages. It receives no security updates — this restores the ability to install, not the ability to patch.

  4. Rebuild the cache.

    Shell
    sudo yum clean all && sudo yum makecache
  5. Understand this is a holding action. The system is out of support and receives no security fixes; plan a migration to Rocky, Alma or RHEL.

    Leaving an EOL distribution on the network indefinitely is a far bigger problem than the one being fixed here.

Confirm it workedyum can list and install packages.
Shell
sudo yum repolist
If you need to undo itsudo rm -rf /etc/yum.repos.d && sudo mv /etc/yum.repos.d.bak /etc/yum.repos.d

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.