centos yum添加aliyun镜像
时间: 2023-11-05 13:52:08 浏览: 63
可以按照以下步骤将阿里云的镜像源添加到 CentOS 的 yum 源列表中:
1. 打开终端并以 root 用户登录您的 CentOS 系统。
2. 进入 yum 源配置文件目录:`cd /etc/yum.repos.d/`
3. 备份 CentOS 系统原有的 yum 源配置文件:`mv CentOS-Base.repo CentOS-Base.repo.backup`
4. 下载阿里云的 yum 源配置文件:`wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo`
5. 使用编辑器打开 yum 源配置文件,找到 `baseurl` 和 `gpgkey` 两行,并在它们的前面加上注释符号 `#`。这样做是为了禁用原有的 CentOS yum 源配置文件,防止 yum 命令在执行时使用 CentOS 源而不是阿里云源:`vim CentOS-Base.repo`
```
[base]
name=CentOS-$releasever - Base
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
# gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
# gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
# gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
# gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
```
6. 保存并关闭文件。
7. 运行 `yum makecache` 命令,更新 yum 缓存,使其立即生效。
现在,您已经成功将阿里云的 yum 源配置文件添加到 CentOS 中了。后续使用 yum 命令安装或升级软件包时,yum 将自动从阿里云的镜像源中获取软件包。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)