centos7更换阿里云yum源
本文介绍了如何在CentOS 7系统中更新yum源。首先,建议备份原有的源文件,使用命令将源文件复制到备份目录。接着,可以通过wget命令从阿里云下载新的源文件,或手动编辑源文件并粘贴新内容。更新源文件后,需清理yum缓存并生成新缓存,以确保系统使用最新的源。最后,通过yum repolist检查新源是否生效,并通过搜索软件包(如nginx)测试新源的功能。这一系列操作确保了系统能够从可靠且最新的
·
1、备份原有源文件
备份原有的源文件,以备不时之需。命令如下:
mkdir /etc/yum.repos.d/backup
cp -rf /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
1、下载新的源文件
下载新的源文件,指令如下:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
当然不想下载,也可以采取如下方法:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
然后直接复制下内容:
**
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
**
保存退出,操作如下:
1、按Esc
2、输入:wq!
3、按Enter
4、生成缓存
配置新的源后,需要清理yum的旧缓存并生成新缓存,指令如下:
sudo yum clean all
sudo yum makecache
5、检查新源
输入以下指令:
yum repolist
6、测试新源
我们随便搜索一个软件包,比如nginx:
yum search nginx
更多推荐
所有评论(0)