【Linux笔记】更换yum源

Centos环境中,执行如下操作时

yum install -y net-tools 安装网络相关命令

报错:

参考博文,更换源:

yum install net-tools报错解决方法-CSDN博客

centos7的yum命令无法使用解决方案_centos7 yum不可用-CSDN博客

更换yum源

1、将yum源相关的文件移动到共享文件夹下

mv /etc/yum.repos.d/CentOS-Base.repo /mnt/hgfs/shared_files

2、Window下查看并修改文件内容

原文件内容:

# 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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

更改后文件内容:

# 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
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
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、将修改后的文件移动到/etc/yum.repos.d

mv /mnt/hgfs/shared_files/CentOS-Base.repo /etc/yum.repos.d 

4、清理yum缓存并更新

yum clean all

yum makecache

yum update

CentOS 7官方于2024/6/30不在维护,找不到相关源了;

清华镜像网址上也已经找不到相关源了。

阿里云镜像网站上目前还有,兴许哪天也会被删除。

这里推荐将相关源下载到本地,然后参考博文,使用本地源配置yum源:

Centos7配置本地Yum源以及网络YUM源(保姆级)_centos7yum源-CSDN博客

### 回答1: 您可以通过修改 /etc/yum.repos.d/ 目录下的 .repo 文件来更换 YUM 源。您也可以通过使用命令行工具 sed,直接替换原有的 yum 配置文件内容,来更改 yum 源。具体操作可以参考相关教程。 ### 回答2: 更换Linux系统中的yum源可以让我们在安装软件时获取更快的下载速度或者获取特定地区的镜像源。 首先,我们需要找到适合的yum源,可以通过搜索引擎或者访问相关网站获取。一般来说,国内常用的yum源有阿里云、清华大学、网易等。 然后,我们需要备份当前的yum源配置文件,以防意外情况发生。通过运行以下命令进行备份: sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 接下来,我们可以通过编辑yum源配置文件来更换源。使用编辑器打开CentOS-Base.repo文件: sudo vi /etc/yum.repos.d/CentOS-Base.repo 我们可以将文件中的baseurl和mirrors字段更改为所需的yum源地址。将baseurl字段更改为新的源地址,如: baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 将mirrors字段更改为新的源地址,如: mirrors=mirrors.aliyun.com 保存文件并退出编辑器。 最后,我们需要清除并重建yum的缓存,通过运行以下命令: sudo yum clean all sudo yum makecache 这样,我们就成功更换Linux系统中的yum源。从现在开始,我们可以使用新源地址来安装软件或更新系统了。记得定期更新yum源,并进行系统的安全升级,以确保系统的稳定和安全。 ### 回答3: 要更换Linux操作系统中的yum源,可以按照以下步骤进行: 1. 首先,备份旧的yum源配置文件(通常在/etc/yum.repos.d/目录下),以防万一出现问题可以快速恢复。 2. 打开终端,并以root用户身份登录。 3. 使用文本编辑器打开yum源配置文件,例如可以使用vi编辑器命令:vi /etc/yum.repos.d/CentOS-Base.repo。 4. 在编辑器中,找到并注释掉原先的baseurl行,将其前面的#号去掉。 5. 修改baseurl为新的yum源地址,可以从官方站点获取新的yum源镜像地址,也可以从社区等其他可信的镜像源获取。 6. 如果需要,还可以更改其他相关的配置,例如启用其他可选的软件包或添加GPG密钥。 7. 保存并退出编辑器。 8. 清空并重建yum缓存,使用命令:yum clean all。 9. 更新yum源,使用命令:yum makecache。 10. 尝试使用yum命令安装或更新软件包,确保yum源已经更换成功。 请注意,更换yum源时应谨慎选择可靠的镜像站点,以确保获取的软件包是经过验证的,并避免下载速度过慢的问题。同时,为了保证系统的安全性和稳定性,建议使用官方或权威的镜像源。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值