CentOS7换yum源

CentOS是Linux系统里最常用的一种,CentOS7的yum源默认是国外的源,相较于国内源,网络连接不够稳定,下载速度较慢,因此我们常常把下载好的CentOS7换源为国内的yum源,本篇文章将介绍如何更换CentOS7的yum源为国内yum源,以阿里云的源为例。

1、备份默认的yum源

切换用户为全权限的root用户,为后面的操作打开通道;
备份默认的repo源,即把原有的.repo文件重命名为.repo.bakeup文件。

su #切换用户为全权限的root用户
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup #备份CentOS-Base.repo为CentOS-Base.repo.backup
yum001 1 - CentOS7换yum源

2、下载阿里云yum源

wget下载阿里云上的Centos-7.repo文件和epel-7.repo到/etc/yum.repos.d/目录下:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下载CentOS-Base.repo 到/etc/yum.repos.d/目录下
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #下载epel-7..repo 到/etc/yum.repos.d/目录下
yum002 1 - CentOS7换yum源
yum003 1 1024x549 - CentOS7换yum源

3、修改repo文件中的链接

sed -i 's/http:\/\/mirrors.cloud.aliyuncs.com/url_tmp/g'  /etc/yum.repos.d/CentOS-Base.repo &&  sed -i 's/http:\/\/mirrors.aliyun.com/http:\/\/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo && sed -i 's/url_tmp/http:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
yum006 1 - CentOS7换yum源

4、清理并重新生成yum缓存

yum clean all #清理yum缓存
yum makecache #重新生成新的yum缓存
yum004 1 - CentOS7换yum源
yum007 2 - CentOS7换yum源

5、用新yum源升级包

yum -y update
yum008 1 - CentOS7换yum源
yum009 1 - CentOS7换yum源
此条目发表在CentOS, Linux分类目录,贴了, , , 标签。将固定链接加入收藏夹。

发表回复