简单几步轻松Linux操作系统切换yum源(以CentOS 7.9配置阿里云的yum源为例)

简介: 本文详细介绍了在CentOS 7.9系统中配置阿里云YUM源的完整步骤:查看系统版本、切换至yum.repos.d目录、备份原有.repo文件、下载适配的CentOS-7.repo、编辑CentOS-Base.repo、最后执行yum clean all && yum makecache更新缓存。操作清晰,附带命令示例与配置说明,适用于运维人员快速优化软件源。



Linux版本:CentOS 7.9(以自己的具体版本选择对应的yum源文件)

以配置阿里云的CentOS 7的yum源为例

一、查看操作系统版本

cat /etc/os-release

cat /etc/system-release

二、切换到/etc/yum.repos.d/目录

cd /etc/yum.repos.d/

ls /etc/yum.repos.d/

三、备份原有的.repo文件

# 备份CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# 创建备份文件夹

mkdir repo.bak

# 备份所有以.repo结尾的文件

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo.bak

四、去官网下载对应版本的yum源文件

配置文件下载,网络源有很多,比如清华、阿里、网易以及其他很多高校都有,这里我们以阿里云的yum源为例,网站地址如下:

阿里云:http://mirrors.aliyun.com/repo/

网易:http://mirrors.163.com/.help/centos.html

清华:https://mirrors.tuna.tsinghua.edu.cn/help/centos/

  • CentOS-7.repo

# CentOS-Base.repo

#

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#

#

 

[base]

name=CentOS-$releasever - Base - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

       http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/

       http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

#released updates

[updates]

name=CentOS-$releasever - Updates - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/

       http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/

       http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/

       http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/

       http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/

       http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/

       http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

#contrib - packages by Centos Users

[contrib]

name=CentOS-$releasever - Contrib - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/

       http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/

       http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

五、创建并编辑CentOS-Base.repo文件

将CentOS-7.repo的内容粘贴到CentOS-Base.repo

vim CentOS-Base.repo

# i

# 将CentOS-7.repo的内容粘贴到CentOS-Base.repo

# esc :wq

六、yum清除缓存并重新建立

yum clean all && yum makecache

# 查看repo列表

yum repolist


相关文章
|
缓存 Ubuntu 前端开发
Linux配置yum源以及基本yum指令
Linux配置yum源以及基本yum指令
|
Linux Shell 数据安全/隐私保护
CentOS-7.9忘记密码如何进入系统
前言 密码记不住一定要备份,重点! 以下步骤旨在提供一个大致的指南。请根据你的系统和问题进行调整,并确保在进行任何更改之前备份重要数据。如果对任何命令不确定,最好先进行额外的研究或咨询。 启动系统并进入 GRUB 引导界面 选择你要引导的Linux系统,并在启动时按下键盘上的 e 键来编辑引导选项。 修改启动参数 在启动参数中找到以 ro 开头的行,将其修改为 rw 并在其末尾添加 rd.break。这将告诉系统在启动时进入临时环境以修改密码。 启动系统
2037 2
|
缓存 Linux 开发工具
CentOS 7- 配置阿里镜像源
阿里镜像官方地址http://mirrors.aliyun.com/ 1、点击官方提供的相应系统的帮助 :2、查看不同版本的系统操作: 下载源1、安装wget yum install -y wget2、下载CentOS 7的repo文件wget -O /etc/yum.
280079 0
|
6月前
|
缓存 Linux
Centos 7配置阿里云yum源
Centos 7配置阿里云yum源
1720 1
|
2月前
|
测试技术 Shell 开发工具
DeepSeek Harness完整实操指南:开源Agent运行框架从安装、模式选型到代码集成
大模型对话产品已经非常普及,但绝大多数对话产品仅仅停留在文本问答层面,模型只能输出文字,无法真正读写本地文件、执行终端命令、自动拆分多步骤任务完成复杂工作。想要让大模型真正操作本机环境,就需要一套Agent运行时框架。DeepSeek Harness(简称DSH),就是2026年8月开源的Agent运行框架,目前处于开发者预览阶段,它的核心思想是**模型负责思考推理,Harness负责执行真实环境操作**。
1024 0
|
4月前
|
存储 网络协议 网络安全
阿里云国际站代理:香港服务器和大陆服务器究竟有什么区别?
本文直击阿里云国际站香港与大陆服务器核心差异:免备案、CN2低延迟(5–25ms)vs 强制ICP备案、国内<10ms但跨境受限;剖析合规、性能、成本与数据主权,助企业避开选型坑点。(239字)
2375 5
dotNetFx40_Full_x86_x64安装步骤详解(附.NET Framework 4.0离线包使用方法)
dotNetFx40_Full_x86_x64.exe是微软.NET Framework 4.0官方安装包,兼容Win7/10/11(32/64位),为老旧工业软件、财务系统等提供运行支持。需以管理员身份运行,安装后必须重启生效。(239字)
|
消息中间件 Java Kafka
在Java中实现分布式事务的常用框架和方法
总之,选择合适的分布式事务框架和方法需要综合考虑业务需求、性能、复杂度等因素。不同的框架和方法都有其特点和适用场景,需要根据具体情况进行评估和选择。同时,随着技术的不断发展,分布式事务的解决方案也在不断更新和完善,以更好地满足业务的需求。你还可以进一步深入研究和了解这些框架和方法,以便在实际应用中更好地实现分布式事务管理。
1467 161
|
Linux 虚拟化 开发者
一键将CentOs的yum源更换为国内阿里yum源
一键将CentOs的yum源更换为国内阿里yum源
24508 31
|
缓存 Linux Perl
CentOS7换yum源
CentOS是Linux系统里最常用的一种,CentOS7的yum源默认是国外的源,相较于国内源,网络连接不够稳定,下载速度较慢,因此我们常常把下载好的CentOS7换源为国内的yum源,本篇文章将介绍如何更换CentOS7的yum源为国内yum源,以阿里云的源为例。
11637 3