插件窝 干货文章 Centos8 无法yum安装软件?

Centos8 无法yum安装软件?

CentOS 方案 repos linux 636    来源:    2025-05-11

CentOS 8 Yum 安装问题解决方案

CentOS 8 默认的 yum 软件源已经停止维护,这会导致 yum install 命令失败。以下是几种解决方案:

方案一:切换到 CentOS Stream 源

sudo dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
sudo dnf distro-sync

方案二:使用 vault.centos.org 源

  1. 备份原有 repo 文件:

    sudo mkdir /etc/yum.repos.d/backup
    sudo mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup/
    
  2. 创建新的 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
    
  3. 创建 /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
    
  4. 清理并重建缓存:

    sudo dnf clean all
    sudo dnf makecache
    

方案三:迁移到 AlmaLinux 或 Rocky Linux

对于长期使用,建议考虑迁移到 CentOS 的替代发行版: - AlmaLinux - Rocky Linux

方案四:使用 EPEL 源

安装 EPEL 源:

sudo dnf install epel-release

常见错误及解决方法

错误: "Failed to download metadata for repo 'AppStream'"

解决: 使用上述任一方案更新软件源

错误: "All mirrors were tried"

解决: 检查网络连接,或尝试更换为 vault.centos.org 源

希望以上方案能解决您的问题。如需更详细的帮助,请提供具体的错误信息。