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

复制代码
相关推荐
TsengOnce几秒前
阿里云ECS多版本JDK切换
java·python·阿里云
代码游侠6 分钟前
学习笔记——写时复制(Copy-on-Write)
linux·网络·笔记·学习·写时复制
被AI抢饭碗的人17 分钟前
linux:线程同步与互斥
linux·开发语言
HalvmånEver27 分钟前
Linux:基础IO(终)
linux·运维·c++·学习·缓冲区·libc
西柚小萌新1 小时前
【计算机常识】--Windows 安装 WSL2 并运行 Ubuntu 22.04
linux·windows·ubuntu
福尔摩斯张1 小时前
基于TCP的FTP文件传输系统设计与实现(超详细)
linux·开发语言·网络·网络协议·tcp/ip·udp
Sleepy MargulisItG1 小时前
【Linux网络编程】应用层自定义协议与序列化
linux·服务器·网络·网络协议·tcp/ip
..过云雨1 小时前
15-2.【Linux系统编程】进程信号 - 信号保存(信号处理流程的三种状态:未决、阻塞、递达,信号保存由未决表完成、sigset_t信号集类型及相关函数)
linux·c++·后端·信号处理
坏一点1 小时前
Yocto项目构建(3)——构建和部署树莓派镜像
linux·驱动开发·嵌入式硬件
Ronin3051 小时前
【Linux网络】多路转接select
linux·网络·select·多路转接