配置好centos后yum安装软件报错,国内环境需要修改源
,
首先备份原文件
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
然后修改文件
vi /etc/yum.repos.d/CentOS-Base.repo
对文件内的mirrorlist进行注释,取消注释baseurl,修改baseurl里的网址为阿里云地址
修改前
[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
修改后,对所有项目进行修改
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
保存退出,然后刷新缓存
yum clean all yum makecache
这时在进行yum安装命令就可以执行成功了
因为centos8已经停止支持,所以使用yum或者dnf进行程序安装会提示
CentOS Linux 8 - AppStream 0.0 B/s | 0 B 00:01 Errors during downloading metadata for repository 'appstream': - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
先进入仓库源文件夹下
cd /etc/yum.repos.d/
2.修改镜像配置内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
3.清空原有缓存,并重新生成
yum clean all && yum makecache
4.更新软件包
yum update -y
安装成功