赞
踩
命令:
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者想用清华的源:
1.粘贴命令。
touch /etc/yum.repos.d/CentOS-Base.repo
2.然后进入这个文件,并把下列配置复制进去。
- # 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=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
-
- #released updates
- [updates]
- name=CentOS-$releasever - Updates
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
-
- #additional packages that may be useful
- [extras]
- name=CentOS-$releasever - Extras
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
- 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
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
- gpgcheck=1
- enabled=0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
yum clean all
yum makecache
无法生成缓存,yum无法使用,如下图。
解决方法:
sudo sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
之后就应该可以成功了,要是还不行,看看有没有网啥的。
问题分析如下:
我开始以为是源本身的问题,但换了其他源之后问题还存在。
可能是:
在使用网络镜像源时,$releasever变量可能无法成功自动识别版本号,此时需要手动设置对应的版本号。
打开我们之前下载的源文件CentOS-Base.repo,下图中画圈的$releasever全部替换成7
主要就是修改baseurl=之后的$releasever,我修改时其他地方没有改依旧可以使用。
如果嫌麻烦,可以使用命令行:
sudo sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
这里的7代表我的系统版本是7,如果你是8就写8
解决之后,用上方第4步测试,成功后就如下,可能会有某个失败,然后换源的情况,这个就是CentOS-Base.repo文件中的baseurl=之后的网址有些无法连接,不过最后只要出现元数据已建立就说明可以正常使用。要是不舒服就换源,或者把不能用的网址删掉。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。