Causes
This error occurs when yum cannot find the required repository metadata at the configured path. Potential causes include:
Operating system end-of-life (EOL): The OS provider has moved the official yum repositories for your EOL version to an archive server (vault), so the original mirror URLs are invalid. You must switch the mirror source to the archive repository. For more information, see handling the OS EOL.
Incorrect HTTP proxy in environment variables: An incorrect HTTP or HTTPS proxy is configured in your environment variables (for example, in the
/etc/profilefile), which prevents yum from connecting to the mirror server. For more information, see check and fix incorrect environment variable configurations.Missing
centos-releasepackage: If this package is missing, yum cannot find any available repositories. yum cannot resolve variables in the configuration files and therefore generates incorrect URLs. For more information, see install the centos-release package.
Solution
Handle the OS EOL
EOL systems are a security risk because they no longer receive security updates. The following steps are a temporary workaround. We strongly recommend that you replace and migrate the operating system as soon as possible.
CentOS 6
Back up the source configuration files.
# Back up the Base source configuration. sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup # Back up the EPEL source configuration. sudo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backupSwitch the Base repository to the archive mirror.
sudo vim /etc/yum.repos.d/CentOS-Base.repoReplace the content of the
CentOS-Base.repofile with the following:[base] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [updates] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [extras] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6Switch the
EPELrepository to the archive mirror.vim /etc/yum.repos.d/epel.repoReplace the content of the
epel.repofile with the following:[epel] name=Extra Packages for Enterprise Linux 6 - $basearch enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/epel-archive/6/$basearch gpgcheck=0 gpgkey=http://mirrors.cloud.aliyuncs.com/epel-archive/RPM-GPG-KEY-EPEL-6Run the
yum repolistcommand. If the command lists the repositories without a 404 error, the issue is resolved.
CentOS 7
Back up the source configuration file.
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupDownload the new source configuration file.
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repoClear and rebuild the yum cache.
yum clean all && yum makecacheRun
yum repolist. If the command lists the repositories without a 404 error, the issue is resolved.
Check and fix incorrect environment variable configurations
Check the proxy environment variables.
echo $http_proxy echo $https_proxyRemove the proxy configuration.
If the previous step returned a proxy address, edit the/etc/profilefile. Find the lines that containexport http_proxy=orexport https_proxy=and comment them out by adding a#at the start of each line.sudo vim /etc/profile# export http_proxy="http://your.proxy.address:port" # export https_proxy="https://your.proxy.address:port"Run the
yum repolistcommand. If the command lists the repositories without a 404 error, the issue is resolved.
Install the centos-release package
Check if the package is installed.
If the command returns
package centos-release is not installed, install the package.sudo rpm -q centos-releaseDownload the package.
Go to the official mirror site, find the latest version of the
centos-release-*.rpmpackage, and copy its link.Replace
<URL>with the copied link.sudo wget <URL>For example, for CentOS 7,
<URL>ishttps://mirrors.aliyun.com/centos/7/os/x86_64/Packages/centos-release-7-9.2009.0.el7.centos.x86_64.rpm.Install the package.
Replace
<file_name>with the filename of the downloaded package.sudo rpm -ivh <file_name>For example, for CentOS 7,
<file_name>iscentos-release-7-9.2009.0.el7.centos.x86_64.rpm.Run the
yum repolistcommand. If the command lists the repositories without a 404 error, the issue is resolved.