Blog / Linux/ Fixing 'Cannot retrieve repository metadata (repomd.xml)' Error on Linode with Yum

Fixing 'Cannot retrieve repository metadata (repomd.xml)' Error on Linode with Yum

解决 Linode 主机 yum 安装出现 Error: Cannot retrieve repository metadata (repomd.xml) 错误

Problem Description

When using yum to install packages on a Linode host, you may encounter an error stating that repository metadata (repomd.xml) cannot be retrieved. The error typically indicates a failure to resolve the domain names for CentOS official mirrors or Linode's internal mirrors.

Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was
14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base.

Root Causes

This error is usually caused by one or more of the following issues:

  • DNS Resolution Failure: The system cannot resolve domain names like mirrorlist.centos.org or mirrors.linode.com.
  • Network Configuration Issues: Firewall rules (e.g., iptables) may be blocking DNS queries or HTTP/HTTPS traffic.
  • Incorrect System DNS Settings: The DNS server configuration in /etc/resolv.conf is incorrect or unavailable.
  • CentOS 6 End of Life: CentOS 6 reached End of Life (EOL) in November 2020. Official mirrors have moved to vault.centos.org, which may cause default repository sources to fail.

Solutions

1. Check and Fix DNS Configuration

First, test if domain name resolution is working:

ping -c 4 google.com
nslookup mirrorlist.centos.org

If resolution fails, edit the /etc/resolv.conf file to ensure valid DNS servers are configured. For Linode hosts, you can add public DNS servers:

nameserver 8.8.8.8
nameserver 8.8.4.4

2. Check Firewall Settings

Temporarily stop the firewall to see if it's causing the issue:

service iptables stop   # CentOS 6
systemctl stop firewalld # CentOS 7/8

If yum works after stopping the firewall, adjust the firewall rules to allow outbound traffic for DNS (port 53) and HTTP/HTTPS (ports 80, 443).

3. Update or Replace Mirror Sources (For Older Systems)

For CentOS versions that have reached EOL (like CentOS 6), replace the base mirror URLs with the archive address (vault.centos.org). Edit the corresponding .repo file (e.g., /etc/yum.repos.d/CentOS-Base.repo) and change mirror.centos.org to vault.centos.org in the mirrorlist and baseurl lines.

For example, change:

baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

to:

baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/

4. Clear Yum Cache and Retry

Run the following commands to clear the cache and try again:

yum clean all
yum makecache

Summary

When encountering the "Cannot retrieve repository metadata" error, first troubleshoot DNS resolution and network connectivity. For older operating systems, also consider whether the mirror sources have become invalid and update them accordingly. It is recommended to upgrade to a supported version (such as CentOS 7/8, AlmaLinux, or Rocky Linux) for ongoing security updates and software support.

Post a Comment

Your email will not be published. Required fields are marked with *.