目录
1. 备份当前yum源
2. 使用wget下载阿里yum源repo文件
3. 清理软件源
4. 把下载的阿里源设置成为默认源
5. 生成阿里yum源缓存并更新yum源
-
备份当前yum源
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base-repo.bak
-
使用wget下载阿里yum源repo文件
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo --2022-05-08 09:14:42-- http://mirrors.aliyun.com/repo/Centos-7.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 221.203.223.99, 60.21.152.88, 221.203.223.103, ... 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|221.203.223.99|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2523 (2.5K) [application/octet-stream] 正在保存至: “Centos-7.repo” 100%[===========================================================================================================>] 2,523 --.-K/s 用时 0s 2022-05-08 09:14:43 (380 MB/s) - 已保存 “Centos-7.repo” [2523/2523])
-
清理软件源
[root@localhost yum.repos.d]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源: base extras updates Cleaning up list of fastest mirrors
-
把下载的阿里源设置成为默认源
[root@localhost yum.repos.d]# mv Centos-7.repo CentOS-Base.repo
-
生成阿里yum源缓存并更新yum源
[root@localhost yum.repos.d]# yum makecache 已加载插件:fastestmirror, langpacks Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; 拒绝连接" 正在尝试其它镜像。 http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误" 正在尝试其它镜像。 base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/10): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:01 (3/10): extras/7/x86_64/primary_db | 246 kB 00:00:00 (4/10): extras/7/x86_64/filelists_db | 277 kB 00:00:00 (5/10): base/7/x86_64/other_db | 2.6 MB 00:00:00 (6/10): extras/7/x86_64/other_db | 147 kB 00:00:00 (7/10): updates/7/x86_64/filelists_db | 8.2 MB 00:00:01 (8/10): updates/7/x86_64/other_db | 1.0 MB 00:00:00 (9/10): updates/7/x86_64/primary_db | 15 MB 00:00:02 (10/10): base/7/x86_64/primary_db | 6.1 MB 00:00:07 元数据缓存已建立 [root@localhost yum.repos.d]# yum update 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com No packages marked for update


![[Linux] CentOS 7 更换阿里源 [Linux] CentOS 7 更换阿里源](http://www.mshxw.com/aiimages/31/870038.png)
