您现在的位置是:首页 >学无止境 >CentOS 7.6更改yum源网站首页学无止境
CentOS 7.6更改yum源
使用字符串替换
我这里的操作参考了https://baijiahao.baidu.com/s?id=1708418392526536542&wfr=spider&for=pc这篇文章,https://mirrors.tuna.tsinghua.edu.cn/help/centos/是清华大学官网教程。
/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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
这样的话需要使用
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g'
-e 's|^#baseurl=http://mirror.centos.org|baseurl=http://mirrors.aliyun.com|g'
-i.bak
/etc/yum.repos.d/CentOS-Base.repo
先进行备份,然后再替换字符串。
现在是备份好了,字符串也替换好了。
yum clean all
清除缓存。
yum makecache
更新缓存。
yum repolist
查看一下yum源是否配置成功。若是能够出现多条记录就是配置成功了,其实这些是配置源里的包,一般都有上万个包。
通过网上下载CentOS-Base.repo
若是不想像上边进行配置的话,使用cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
将CentOS-Base.repo复制为CentOS-Base.repo.bak。
然后使用下边三个wget命令中一个就可以获取.repo
文件,只需要执行一次。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
可以获取阿里云yum源配置文件到/etc/yum.repos.d/目录下并更名为CentOS-Base.repo。
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
可以获取华为云yum源配置文件到/etc/yum.repos.d/目录下并更名为CentOS-Base.repo。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
获取网易yum源配置文件到/etc/yum.repos.d/目录下并更名为CentOS-Base.repo。
然后再依次执行下边的命令:
yum clean all
清除缓存。
yum makecache
更新缓存。
yum repolist
查看一下yum源是否配置成功。