Linux系列之如何更换Centos yum源?

发布于:2024-12-18 ⋅ 阅读:(67) ⋅ 点赞:(0)

在这里插入图片描述

环境

  • Centos7
  • Xshell7

问题描述

最近安装了一个虚拟机,准备用来学习,不过使用yum命令安装一些软件,不过使用这个命令时候,提示

Cannot find a valid baseurl for repo: base/7/x86_64,Could not retrieve mirrorlist

具体报错截图:
在这里插入图片描述

解决方法

这种问题,一般有几种情况:

  1. 网络问题,可以在虚拟机里ping一下域名
  2. DNS问题,需要修改配置 /etc/sysconfig/network-scripts/
  3. Centos yum源有问题,需要更换repo
  • 检查网络问题
    在虚拟机里,ping一下百度的域名,能ping通说明网络正常
    在这里插入图片描述
  • 检查DNS配置

到这个目录

 cd /etc/sysconfig/network-scripts/

一般是找到ifcfg-en这样开头的文件
在这里插入图片描述
vi查看这个文件,检查ONBOOT是否设置为yes,不是修改为yes,然后!wq保存退出
在这里插入图片描述

  • 更换Centos yum源
    前面网络和dns都检查了,都正常,不过yum下载还是提示报错,所以需要换一个yum源看看,使用国内的yum源

阿里云 CentOS 7 源:http://mirrors.aliyun.com/repo/Centos-7.repo
华为云 CentOS 7 源:http://mirrors.myhuaweicloud.com/repo/CentOS-7.repo
网易163 CentOS 7 源:http://mirrors.163.com/.help/CentOS7-Base-163.repo
搜狐 CentOS 7 源:http://mirrors.sohu.com/help/CentOS7-Base-sohu.repo

本文使用阿里云的repo,先检查一下系统有wget? 有的话直接wget下载一下repo文件

先备份一下原本的repo文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

wget下载阿里云的repo文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

如果系统没有wget,那就去阿里云官网下载一下,链接: https://mirrors.aliyun.com/repo/

在这里插入图片描述
然后使用xftp上传到服务器,移动到/etc/yum.repos.d/

cp Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo

然后就可以使用yum命令,安装一下wget

yum install wget

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到