配色

▤ CentOS7更换yum源

服了

https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11o53Rj3

报错

在CentOS中用yum安装时报错。

Image_18FAA09F53A2F3B86EF411568A21F945

原因

CentOS 7 的生命周期已经结束,CentOS 7 的官方仓库在 2024 年 6 月 30 日之后已经停止维护。

解决方法

首先进入CentOS-Base.repo的目录。

1
2
cd /etc/yum.repos.d #进入目录
ls #列出目录下所有文件

Image_2313A9F472F94DFC385369BC5F815193

我们需要对CentOS-Base.repo进行修改。

1
2
cp CentOS-Base.repo  CentOS-Base.repo.backup  #备份CentOS-Base.repo
vi CentOS-Base.repo #使用vi修改CentOS-Base.repo

进入编辑器后,我们按下Shift+;,在屏幕下方出现: 后,我们输入%d删除所有内容。

然后按下i键进入插入模式

将下方全部字样粘贴进清空后的编辑器。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/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/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/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/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/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/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

确认无误后,按下ESC回到命令行模式,按下Shift+;,在屏幕下方出现: 后,输入wq,回车退出。

接下来我们清理 YUM 缓存并重新生成缓存

✎ 留言讨论(…)

评论加载中…

评论由站长自建服务提供 · 像素头像按昵称自动生成