有时候 CentOS 默认的 yum 源不一定是国内镜像,导致 yum 在线安装及更新速度不是很理想。这时候需要将 yum 源设置为国内镜像站点。
国内主要开源的开源镜像站点应该是网易和阿里云了,下面以修改 yum 镜像源为网易镜像源为例。
备份原有yum配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
替换配置文件
进入yum源配置文件目录 /etc/yum.repos.d
,下载网易源配置文件:
cd /etc/yum.repos.d
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
这里我是以 CentOS 7 为例,如果你的版本不同,则修改对应地址即可,CentOS 各版本对应源配置文件地址如下:
- 网易 CentOS 7:http://mirrors.163.com/.help/CentOS7-Base-163.repo;
- 网易 CentOS 6:http://mirrors.163.com/.help/CentOS6-Base-163.repo;
- 网易 CentOS 5:http://mirrors.163.com/.help/CentOS5-Base-163.repo;
- 阿里 CentOS 7:http://mirrors.aliyun.com/repo/Centos-7.repo;
- 阿里 CentOS 6:http://mirrors.aliyun.com/repo/Centos-6.repo;
- 阿里 CentOS 5:http://mirrors.aliyun.com/repo/Centos-5.repo;
生成缓存
先清理原来的 yum 源缓存:
yum clean all
重新生成缓存:
yum makecache
测试
查看 yum 仓库源名称确认仓库源是否已经切换到网易源~
[root@localhost ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
!base/7/x86_64 CentOS-7 - Base - 163.com 10,097
!extras/7/x86_64 CentOS-7 - Extras - 163.com 305
!updates/7/x86_64 CentOS-7 - Updates - 163.com 685
repolist: 11,087
epel源安装
安装阿里云 epel 源:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo
评论区