便宜vps推荐
搬瓦工优惠|主机测评网!

yum源更换为阿里云教程,解决yum源失效报错

现在很多VPS主机商提供的系统yum源都失效了,这对于一个不会Linux系统运维的小白来说非常麻烦。当你看到出现“Failed to download metadata for repo ‘AppStream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist”等类似的报错,那就是Centos系统的yum源失效了。如果你现在的yum在线下载速度不是特别理想,也可以将yum源切换为国内镜像,下面就教大家如何将vps的yum源切换为阿里云。

CentOS7系统

1.首先备份系统自带yum源配置文件 /etc/yum.repos.d/CentOS-Base.repo

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

2.下载国内yum源配置文件到 /etc/yum.repos.d/

阿里源(推荐):

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

网易源:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

如果vps没有安装wget,就用curl命令

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

3.更新下载源地址

sed -i -e"s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-*

sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*

4.清理yum缓存,并生成新的缓存

yum clean all
yum makecache

5.更新yum源检查是否生效

yum update

 

CentOS8系统

只需要将第2步的代码更换一下(下载CentOS8的yum源文件)

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

或者curl

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

相关问题

如果出现类似报错

Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

个错误表明你的CentOS 8系统在尝试从appstream仓库下载元数据时遇到了问题。具体来说,错误提示是“Cannot prepare internal mirrorlist: No URLs in mirrorlist”,意味着在尝试准备内部镜像列表时,没有找到任何URL。CentOS 已经停止维护的问题。由于CentOS 8的官方支持在2021年底结束,一些官方仓库可能已经不再维护或更新。

解决方法

#进入到 yum 的 repos 目录
cd /etc/yum.repos.d/
#注释原mirrorlist行
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
#替换yum源url地址
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
#重建yum缓存
yum makecache

 

 

国内镜像汇总

阿里yum源:http://mirrors.aliyun.com/repo/
163(网易)yum源: http://mirrors.163.com/.help/
中科大的Linux安装镜像源:http://centos.ustc.edu.cn/
搜狐的Linux安装镜像源:http://mirrors.sohu.com/
北京首都在线科技:http://mirrors.yun-idc.com/

赞(0)
未经允许不得转载:雪花测评 » yum源更换为阿里云教程,解决yum源失效报错

推荐使用腾讯云轻量级应用服务器建站,开箱即用:点我进入

登录

找回密码

注册