为什么更换
linux系统的默认yum源为centos的官方地址,在“国内的特殊环境”下使用很慢甚至无法访问,所以我们一般考虑都是把默认的yum源替换成aliyun、清华、网易等国内的yum源,去加快访问速度。
软件源的选择
一些常见的国内源:
1.网易镜像源及帮助文档:
http://mirrors.163.com/
http://mirrors.163.com/.help/centos.html
2.阿里镜像源及帮助文档:
https://developer.aliyun.com/mirror/
https://yq.aliyun.com/articles/518796
3.清华镜像源:
https://mirrors.tuna.tsinghua.edu.cn/
4.中科大镜像源:
http://oss.ustc.edu.cn/
等等,类似还有很多,这里不再列举了…
操作过程
我们使用清华的软件源来举例
推荐进行以下操作时请先备份!!!
# 清除缓存
[root@localhost ~]# yum clean all
#非root用户请执行以下命令时加上sodu
[root@localhost ~]# rm -rf /var/cache/yum
# 卸载epel仓库
[root@localhost ~]# yum remove epel-release
# 删除所有旧仓库文件
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
操作过程示例:
# 新建仓库文件
vi /etc/yum.repos.d/CentOS-Base_resource.repo
########################################增加以下内容######################################
# CentOS-Base_resource.repo
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
最后执行以下命令就可以了
# 建立缓存
yum makecache
# 重新安装EPEL仓库
yum install epel-release
最后附上成功截图:
留在最后
自己最近在学习git和Docker,需要用到Linux,尤其是Docker技术,最好是装在Linux上,由于Linux发行版众多,如果选用CentOS的话建议考虑CentOS7及以上版本。由于本人的技术水平有限,此次博客只作为记录更换软件源的笔记。百度上很多帖子对更换软件源说的都非常透彻,感谢众多技术大佬对此的解答。
操作过程参考自:https://blog.csdn.net/f110300641/article/details/81708070