虚拟机已经连上网可是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 源已经成功修改为阿里云的镜像源。现在可以尝试安装 了。

复制代码
相关推荐
WAsbry1 天前
InputConnection机制与跨进程文本操作的工程实践
android·linux
wdfk_prog1 天前
[Linux]学习笔记系列 -- [kernel]cpu
linux·笔记·学习
WAsbry1 天前
从一个Bug看Android文本编辑的设计缺陷
android·linux
大聪明-PLUS1 天前
Linux 中 timeout、watch 和 at 的指南:管理命令执行时间
linux·嵌入式·arm·smarc
想唱rap1 天前
Linux开发工具(4)
linux·运维·服务器·开发语言·算法
robin59111 天前
Linux-通过端口转发访问数据库
linux·数据库·adb
视觉AI1 天前
如何查看 Linux 下正在运行的 Python 程序是哪一个
linux·人工智能·python
扣脚大汉在网络1 天前
如何在centos 中运行arm64程序
linux·运维·centos
lang201509281 天前
Linux命令行:cat、more、less终极指南
linux·chrome·less
攒钱植发1 天前
嵌入式Linux——“大扳手”与“小螺丝”:为什么不该用信号量(Semaphore)去模拟“完成量”(Completion)
linux·服务器·c语言