Centos8系统在安装Git包时,报错:“没有任何匹配: git”

报错类型:

复制代码
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

至此问题解决。

相关推荐
Leo.yuan8 小时前
Agent化分析加速成形:FineBI AI原生技术架构落地,推动AI+BI分析范式跃迁
大数据·人工智能
YH行业报告分析9 小时前
2026商用鸡蛋分级机深度分析:AI视觉分拣如何驱动蛋品加工智能化升级?
大数据·科技·智能
DolphinDB智臾科技9 小时前
插件上新 | 让 Excel 数据更顺畅地接入 DolphinDB
大数据·excel
MinggeQingchun9 小时前
Git - 令牌登录
git
云安全助手9 小时前
自建接入VS聚合平台:企业 AI 调用的选型思路与迁移成本拆解
java·大数据·数据库·人工智能·ai大模型
Gu_WenYun9 小时前
从全面普涨到双轨分化,如何用基金布局存储芯片?
大数据·人工智能·业界资讯
陈工大模型9 小时前
GEO监测工具技术选型:2026年9月AI可见性十强评测
大数据·人工智能·科技
CallFay云起未来10 小时前
AI客服上线后多久才能回本?从TCO到ROI的完整测算方法
java·大数据·人工智能·架构·文心一言
Elastic 中国社区官方博客10 小时前
使用 Lucene 搜索你的 Bean —— Elasticsearch
大数据·开发语言·人工智能·elasticsearch·搜索引擎·全文检索·lucene
闲蛋小超人笑嘻嘻10 小时前
Git Worktree 详解
大数据·elasticsearch·搜索引擎