前言
yum(Yellowdog Updater Modified)是一个在 CentOS
、Fedora 和其他基于 Red Hat
的 Linux 发行版上常用的包管理器。Yum 负责从软件仓库中下载并安装软件包,并解决软件包之间的依赖关系。
默认情况下,CentOS 使用的是官方的 Yum 源,但有时用户可能希望将 Yum 源切换到国内的源
以提高下载速度和稳定性
,特别是对于国内用户。(因为国内 Yum 源具有地理位置近、网络带宽高、稳定性好等优势,能更快下载软件包,及时更新,提高系统安装和维护效率。)
提示:先去学一下vim
的使用
安装国内源的步骤
方法一
备份原始 Yum 配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-backup.repo
修改文件
vim /etc/yum.repos.d/CentOS-Base.repo
添加下面的内容覆盖全部以前的内容
[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
方法二
备份原始 Yum 配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base-backup.repo
下载国内的 Yum 源配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
刷新 yum 缓存
yum makecache
使用已更换的源进行系统软件包的更新
yum -y update
补充
wget
是一个命令行工具,用于从网络上下载文件。它支持通过 HTTP、HTTPS 和 FTP 协议下载文件,并且具有灵活的选项,可以用来执行各种下载任务。
方法一要先清除源文件里面的内容。可以用echo " " > /etc/yum.repos.d/CentOS-Base.repo
也可以用vim,在命令模式下(编辑模式退出命令模式:ESC
键盘左上角这个键),两次点击D就可以删除一行
觉得有用点个👍,谢谢