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

261 阅读1分钟

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文件内容为空) 直接在浏览器通过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