解决yum 安装包时报错

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total 40
-rw-r--r--. 1 root root 1664 Oct 23  2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23  2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 23  2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 23  2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 23  2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23  2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23  2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 23  2020 CentOS-x86_64-kernel.repo

备份CentOS-Base.repo

cp CentOS-Base.repo CentOS-Base.repo.bak

vi /etc/yum.repos.d/CentOS-Base.repo
:%s/$releasever/7.9.2009/g					 //将所有$releasever替换成7.9.2009
:%s/CentOS-7.9.2009/CentOS-Base/g			 //将CentOS-7.9.2009替换成文件名CentOS-Base
:wq!

注意事项
$releasever应替换成相对应的系统版本
name=CentOS-Base这里也要改成你自己的文件名,比如阿里云的文件名是Centos-7.repo,那就改成name=CentOS-7

下面是centos7.9.2009版本的yum源

# 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-Base - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-Base - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&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-Base - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&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-Base - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 yum makecache
  yum update


版权声明:本文为lotus_struggle原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。