CentOS 8 默认的 yum 软件源已经停止维护,这会导致 yum install
命令失败。以下是几种解决方案:
sudo dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
sudo dnf distro-sync
备份原有 repo 文件:
sudo mkdir /etc/yum.repos.d/backup
sudo mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup/
创建新的 repo 文件 /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
:
[baseos]
name=CentOS Linux $releasever - BaseOS
baseurl=http://vault.centos.org/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
创建 /etc/yum.repos.d/CentOS-Linux-AppStream.repo
:
[appstream]
name=CentOS Linux $releasever - AppStream
baseurl=http://vault.centos.org/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
清理并重建缓存:
sudo dnf clean all
sudo dnf makecache
对于长期使用,建议考虑迁移到 CentOS 的替代发行版: - AlmaLinux - Rocky Linux
安装 EPEL 源:
sudo dnf install epel-release
错误: "Failed to download metadata for repo 'AppStream'"
解决: 使用上述任一方案更新软件源
错误: "All mirrors were tried"
解决: 检查网络连接,或尝试更换为 vault.centos.org 源
希望以上方案能解决您的问题。如需更详细的帮助,请提供具体的错误信息。