虚拟机已经连上网可是yum用不了,可以将 CentOS 的 yum 源镜像修改为阿里云的镜像源(http://mirrors.aliyun.com/)

可以通过以下步骤将 CentOS 的 yum 源镜像修改为阿里云的镜像源。

1. 备份现有的 yum 源配置文件

首先,备份现有的 yum 源配置文件,以防需要恢复原来的设置。

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2. 下载阿里云的 yum 源配置文件

下载并替换为阿里云的 yum 源配置文件。

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3. 清除缓存并生成新的缓存

清除 yum 缓存,并生成新的缓存。

yum clean all
yum makecache

示例完整过程

以下是一个完整的操作示例:

[root@localhost ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2024-07-21 03:30:00--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... (IP address)
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)| (IP address)|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: (number of bytes)
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

/etc/yum.repos.d/CentOS-Base.repo 100%[================================================>]  (number of bytes)   in (seconds) 

2024-07-21 03:30:05 (number of bytes/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [number of bytes/number of bytes]

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up everything
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                 | 3.6 kB     00:00     
extras                                               | 2.9 kB     00:00     
updates                                              | 2.9 kB     00:00     
Metadata Cache Created

这样, yum 源已经成功修改为阿里云的镜像源。现在可以尝试安装 了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值