如何将CentOS的yum源更换为阿里云源

一、yum源简介

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。 (来自百度百科)

默认yum源为CentOS官方源:mirrorlist.centos.org

因其服务器在国外,直接从官方源下载安装软件时稳定性、速度等有时并不是很好,国内有如阿里云源、网易源等镜像站点,比官方源更稳定、速度更快。

二、yum安装软件命令

安装软件(以foo-x.x.x.rpm为例):yum install foo-x.x.x.rpm

删除软件:yum remove foo-x.x.x.rpm或者yum erase foo-x.x.x.rpm

升级软件:yum update foo或者yum update foo

查询信息:yum info foo

三、修改yum源为阿里云

3.1 yum源配置文件路径:

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

3.2 查看CentOS-Base.repo文件内容:

cat /etc/yum.repos.d/CentOS-Base.repo

root@sheng yum.repos.d\]# cat CentOS-Base.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

root@sheng yum.repos.d\]# 3.3 备份官方源配置: cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 3.4 下载阿里云yum源配置文件覆盖原官方源配置文件: curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 此时该文件( /etc/yum.repos.d/CentOS-Base.repo)已是阿里云yum源配置文件,可用 cat /etc/yum.repos.d/CentOS-Base.repo 查看文件内容。 3.5 清理缓存并生成新的缓存: yum clean all yum makecache 3.6 更新软件 sudo yum -y update 完 注意:如果Linux 机器中没有CURL 命令,可以COPY 项目aliyun 上面repo 的内容。

相关推荐
Johny_Zhao1 小时前
阿里云平台健康检查巡检清单-运维篇
linux·网络安全·阿里云·信息安全·云计算·shell·系统运维
来自于狂人1 小时前
CentOS 镜像源配置与 EOL 后的应对策略
linux·运维·centos
博语小屋2 小时前
进程初识之进程状态
linux
吉凶以情迁2 小时前
window服务相关问题探索 go语言服务开发探索调试
linux·服务器·开发语言·网络·golang
数智前线3 小时前
谁在托举Agent?阿里云抢滩Agent Infra新赛道
阿里云·云计算
潮湿的心情3 小时前
中宇联:以“智云融合+AI”赋能全栈云MSP服务,深化阿里云生态合作
人工智能·阿里云·云计算
云布道师3 小时前
【云故事探索】NO.16:阿里云弹性计算加速精准学 AI 教育普惠落地
人工智能·阿里云·云计算
阿里云云原生3 小时前
阿里云微服务引擎 MSE 及 API 网关 2025 年 7 月产品动态
阿里云·微服务·云计算
柏木乃一4 小时前
Linux初步认识与指令与权限
linux·运维·服务器·shell·权限
Joemt4 小时前
ubuntu源码编译安装cmake高版本、pybind11安装、crow使用
linux·运维·ubuntu