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

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

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

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

sh 复制代码
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

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

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

sh 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

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

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

sh 复制代码
yum clean all
yum makecache

示例完整过程

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

sh 复制代码
[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 小时前
Linux网络:数据链路层
linux·服务器·开发语言·网络·c++·后端
fish_xk11 小时前
Linux基础指令。
linux·运维·服务器
WL_Aurora11 小时前
MySQL 8.0 在 Linux 下的深度配置与实战指南
linux·mysql
代码中介商11 小时前
Linux多线程编程完全指南(续):条件变量、读写锁与线程安全函数
linux·开发语言
计算机安禾11 小时前
【Linux从入门到精通】第42篇:深入理解Linux内存管理
android·linux·运维
艾莉丝努力练剑11 小时前
【Linux网络】Linux 网络编程入门:UDP Socket 编程(上)
linux·运维·服务器·网络·c++·udp
代码中介商11 小时前
Linux多线程编程完全指南:线程同步、互斥锁与生产者消费者模型
linux·运维·服务器
计算机安禾11 小时前
【Linux从入门到精通】第43篇:I/O调度算法与磁盘性能优化
linux·算法·性能优化
计算机安禾11 小时前
【Linux从入门到精通】第44篇:Linux网络协议栈与TCP参数调优
linux·网络协议·tcp/ip
rleS IONS11 小时前
Linux系统离线部署MySQL详细教程(带每步骤图文教程)
linux·mysql·adb