CentOS更新YUM仓库源

1、备份现有的YUM配置文件

cp -r /etc/yum.repos.d /etc/yum.repos.d.backup

2、编辑或替换仓库配置文件

检查/etc/yum.repos.d/CentOS-Base.repo文件。确保baseurlgpgcheck配置正确。你可以手动编辑这个文件,或者更换为可靠的YUM仓库源

示例:

更换为阿里源

编辑/etc/yum.repos.d/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
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 编辑完成保存并退出

3、清理并重建缓存

yum clean all
yum makecache
yum update -y

更新 CentOS 中的 `yum` ,可以按照以下步骤操作: ### 步骤一:备份当前的 yum 配置文件 1. 打开终端并输入以下命令以移动(备份)当前的 `yum` 配置文件到 `.backup` 目录下: ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` ### 步骤二:下载新的 yum 列表 访问 CentOS 官方的镜像站点,并选择适合您所在地区的镜像。例如,可以通过访问 `https://mirrors.aliyun.com/centos/` 来找到适合中国的。之后下载最新的 `CentOS-Base.repo` 文件。 ### 步骤三:上传新的 yum 文件 将下载的 `CentOS-Base.repo` 文件通过 FTP 或 SCP 等方式上传至 `/etc/yum.repos.d/` 目录下。假设您已经下载了名为 `new_centos_base.repo` 的文件,则执行: ```bash scp new_centos_base.repo user@your_server_ip:/etc/yum.repos.d/ ``` 使用 `ssh` 连接到您的服务器,确认文件已成功上传。 ### 步骤四:验证新设置 完成上述步骤后,您可以重启 `yum` 服务来加载新的配置,然后再测试更新功能: ```bash systemctl restart yum ``` 接着运行 `yum repolist` 查看可用的仓库列表以及它们的状态,确保新已正确启用。 ### 步骤五:更新软件包 确认设置无误后,您可以开始更新软件包: ```bash yum update ``` 这将会尝试更新所有可更新的软件包。请注意,更新过程可能会带来一些风险,如依赖关系冲突或不兼容性问题,因此务必谨慎操作。 --- ## 相关问题 - centos更新yum: 1. 如何验证新的yum是否已经生效? 2. 如果在更新过程中遇到错误,应该如何解决? 3. 是否有替代方案可以在线更新yum而无需手动上传文件?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值