将yum默认的下载源更换为国内的源能使下载速度更快。我选择了阿里的源,同样也可以选择网易163或者其他的。网址:阿里云开源镜像站 https://opsx.alibaba.com/mirror
更换源方法如下:
在镜像站首页找到自己的Linux版本(我的是CentOS 7.4),点击help。新打开的网页中详细的说明了如何备份,如何更换镜像源(在Linux的Terminal中):
1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS5:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS6:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS7:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、之后运行yum makecache生成缓存
yum clean all
yum makecache
PS:更换完源进行下载或者生成缓存时可能遇到以下错误:
[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found" Trying other mirror.
[Errno 14] PYCURL ERROR 7 - "couldn't connect to host" Trying other mirror.
[Errno 256] No more mirrors to try.
有效的解决方法:
yum clean all
rpm --rebuilddb
执行完上述两条语句重新使用yum下载或者生成缓存即可成功