文章目录

CentOS7 更换镜像源

  • 1.先安装wget
  • 2.下载CentOS 7的对应的repo文件
  • 3.更新镜像源

使用yum install -y xxx 或者 yum makecache时,报错Could not resolve host: mirrorlist.centos.org

CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)_yum

CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)_yum_02

解决方法:看到报错日志中加粗的字体,命令行ping mirrorlist.centos.org 不通。试着ping www.baidu.com是正常的,说明DNS解析没问题。基本确认是yum源的问题

CentOS7 更换镜像源

1.先安装wget

wget --version    #如果已有wget,则跳过安装、直接进行第二步
yum install -y wget
wget --version

2.下载CentOS 7的对应的repo文件

#先备份CentOS-Base.repo
mv CentOS-Base.repo CentOS-Base.repo.backup


#下载CentOS 7的对应的repo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

如果wget提示报错,wget: unable to resolve host address ‘mirrors.aliyun.com’,(此时/etc/yum.repos.d/CentOS-Base.repo文件内容为空)

CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)_镜像源_03

直接在浏览器通过http://mirrors.aliyun.com/repo/Centos-7.repo 下载Centos-7.repo,然后将其传到/etc/yum.repos.d目录下,重命名为CentOS-Base.repo

cd /etc/yum.repos.d
mv Centos-7.repo CentOS-Base.repo
cat CentOS-Base.repo

CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)_yum_04

3.更新镜像源

yum clean all
yum makecache
yum -y update

执行完上面三行命令,便可通过yum下载其他软件了。