暂无图片
请问在centos7系统上使用yum源安装软件包时总是报错,什么原因导致的?怎么有效解决此问题?
我来答
分享
努力努力再努力
2025-06-08
请问在centos7系统上使用yum源安装软件包时总是报错,什么原因导致的?怎么有效解决此问题?
暂无图片 300M

在centos7系统上使用yum命令yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel ,详细报错信息如下:


已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


One of the configured repositories failed (未知),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

1. Contact the upstream for the repository and get them to fix the problem.

2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).

3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...

4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:

yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>

5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:

yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64

我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
smile

有效的解决方法如下:
由于 CentOS 7 官方仓库已停止维护,必须 手动替换为国内镜像源(如阿里云、清华源)。
1.备份并删除原有仓库
sudo mkdir -p /etc/yum.repos.d/backup
sudo mv /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/backup/
2.下载阿里云或清华的仓库配置
选项 1:阿里云镜像
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
选项 2:清华镜像
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/centos7.repo
选项 3:华为云镜像
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
3.检查仓库文件是否正确
cat /etc/yum.repos.d/CentOS-Base.repo | head -n 5
正确示例:
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
如果文件是 HTML(错误),说明下载失败,手动复制内容到文件。
4.清理 YUM 缓存并重建
sudo yum clean all # 清理缓存
sudo yum makecache # 重建缓存
5.重新安装 OpenJDK 8
sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
6.检查 Java 是否安装成功
java -version

暂无图片 评论
暂无图片 有用 0
暂无图片
德川家坑

有两个需要确认的情况:
1、你这台centos7是否可以连接公网

2、主要报错为"Could not resolve host: mirrorlist.centos.org;这一段,我看应该是使用默认的repo配置导致的,最好是更换成国内的镜像源;或者把iso挂在到服务器上再修改repo进行安装就可以了。

暂无图片 评论
暂无图片 有用 0
沐炎

1.备份原始 yum 源:
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载阿里云 CentOS 7 镜像源配置:
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.清理并更新缓存:
sudo yum clean all
sudo yum makecache

暂无图片 评论
暂无图片 有用 1
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏