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

复制代码
相关推荐
水天需0101 分钟前
PS 例程大全
linux
源宇宙十三站4 分钟前
Linux故障诊断系列2.3-诊断系统启动问题-Server启动失败该如何处理
linux
橘子真甜~1 小时前
C/C++ Linux网络编程13 - 传输层TCP协议详解(面向字节流和有连接)
linux·运维·服务器·c语言·网络·c++·tcp/ip
嘻哈baby1 小时前
systemd服务管理深入实践从入门到自定义服务
linux·服务器·网络
June`1 小时前
SSH连接原理与守护进程实战
linux·运维·服务器
我是六月生1 小时前
于windows环境下,使用阿里云oss搭建在线图床,Obsidian/Typora自动将图片上传,实现图片粘贴复制
笔记·阿里云·云计算
水天需0101 小时前
Grep 例程大全
linux
杼蛘1 小时前
XXL-Job工具使用操作记录
linux·windows·python·jdk·kettle·xxl-job
CQ_YM2 小时前
Linux进程基础
linux·服务器·进程
_OP_CHEN2 小时前
【Git原理与使用】(五)Git 多人协作:从分支协作到冲突解决,团队开发效率翻倍秘籍
linux·运维·git·团队开发·运维开发·企业级组件·git多人协作