報錯類型:
sudo dnf install git
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository fasttrack is listed more than once in the configuration
上次元數據過期檢查:0:05:59 前,執行于 2025年08月11日 星期一 17時01分07秒。
未找到匹配的參數: git
錯誤:沒有任何匹配: git
報錯原因:
CentOS 8 已經在 2021-12-31 EOL(停止維護),官方倉庫下線,所以留下來的 CentOS-Base.repo 文件里的地址已經 404,導致 dnf 直接跳過它,也就找不到任何系統基礎包(包括 git)。
解決辦法:
把系統倉庫全部換成 CentOS-Vault 或第三方鏡像源。
下面給出最簡操作(以阿里云 CentOS-Vault 為例,對應 CentOS 8.5.2111):
# 1. 進入倉庫目錄
cd /etc/yum.repos.d/# 2. 如果剛才沒備份,再備份一次
sudo mkdir -p backup
sudo mv CentOS-Base.repo backup/CentOS-Base.repo.bak# 3. 下載可用的 vault 源
sudo curl -o CentOS-Vault.repo \https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/x86_64/os/Packages/centos-release-8.5-1.2111.el8.noarch.rpm# 實際上上面這個 URL 是 rpm 包,我們需要直接拉取 repo 文件
# 用下面這個一次性腳本最省事(復制整段執行):
sudo tee CentOS-Vault.repo >/dev/null <<'EOF'
[BaseOS]
name=CentOS-8.5.2111 - BaseOS
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial[AppStream]
name=CentOS-8.5.2111 - AppStream
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial[extras]
name=CentOS-8.5.2111 - Extras
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
清理緩存并重建
sudo dnf clean all
sudo dnf makecache
安裝 git
sudo dnf install git
執行完后就能正常找到并安裝 git 了。
如果提示缺 RPM-GPG-KEY-centosofficial,再執行:
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial# 或直接手動下載:
sudo curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial \https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official
全部完成后驗證:
git --version
輸出示例:
git version 2.27.0
至此問題解決。