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

复制代码
相关推荐
爱和冰阔落17 分钟前
【Linux网络】UDP 服务器怎么写?从 socket、bind 到 recvfrom/sendto,手写完整回显服务器
linux·运维·服务器·网络
maochongsandai11020 分钟前
Centos上运行docker应用命令汇总
linux·docker·centos
一只QAQ28 分钟前
python语法学习
linux·python·学习
by209991 小时前
Linux 软件安装与 Vim 编辑
linux·经验分享·vim
CQU_JIAKE1 小时前
10.28【A】
linux·运维·网络
大力财经1 小时前
山东山大华天软件与阿里云达成合作,旗下产品CrownCAD已接入Qoder
人工智能·阿里云·云计算
爱和冰阔落1 小时前
【Linux网络】Socket 编程前要搞懂什么?从 IP、端口到字节序与 sockaddr,一次理清网络通信基础
linux·运维·网络·tcp/ip
晚风叙码1 小时前
Linux 进程概念(上):从冯诺依曼到进程调度
linux·运维·计算机外设
邪修king1 小时前
Re:Linux系统篇(三十八):进程间通信ChapterSystem V 信号量深度解析|同步互斥、内核源码、C 指针多态、实战代码
java·linux·c语言
坤坤子吖1 小时前
Linux网络编程基础:从 MAC 到 IP,理解网络数据是怎么传输的
linux·网络·笔记·学习