第一步:删除系统自带yum包
# rpm -qa |grep yum //查询本地的yum
# rpm -qa |grep yum|xargs rpm -e --nodeps //不检查依赖直接删除rpm包
# rpm -qa |grep yum //如果无内容则表示卸载完毕
第二步:进入# cd /etc/yum.repos.d/
cd /etc/yum.repos.d/
开始下载yum所需要的rpm。
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-3.2.27-14.el6.centos.noarch.rpm
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-3.2.27-14.el6.centos.noarch.rpm
wget --no-check-certificate https://mirrors.aliyun.com/centos-vault/6.0/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.26-11.el6.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
python-2.7.5-89.el7.x86_64.rpm
安装rpm
rpm -ivh yum-*
rpm -ivh --force --nodeps python-urlgrabber-3.10-10.el7.noarch.rpm
第三步 下载阿里云的yum源:
编辑/etc/resolv.conf文件,添加如下代码
-
nameserver 223.5.5.5
-
nameserver 223.6.6.6
然后 :wq 保存退出。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
从这里下载repo文件到/etc/yum.repos.d/目录
wget http://mirrors.aliyun.com/repo/Centos-7.repo
或者:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
编辑 Centos-7.repo
vim Centos-7.repo
使用全文替换:
:1,$s/$releasever/7
第四步:输入yum测试
如果出现 下面表示 python版本不匹配
[root@localhost yum.repos.d]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.6.5 (r265:79063, Oct 31 2021, 00:53:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
解决办法:
查看python版本
python -V
Python 2.7.3
查看python位置
whereis python
python: /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/include/python2.7 /usr/local/python2.7 /usr/share/man/man1/python.1.gz
修改yum的python版本
vi /usr/bin/yum
修改第一句内容为以下
/usr/bin/python
#!/usr/bin/python2.6
如果还不行就要提高的python版本
重新安装完之后python ,还不行的话, 就在卸载 yum 从第一步走一遍。
最后:重新生成缓存,数字不为0,就OK了:
yum clean all
yum makecache
linux 其他命令:
java -version 检测当前系统是否存在Java环境 和windows命令一样
#如果有的话就需要卸载
rpm -qa|grep jdk 查看JDK版本信息
rpm -e --nodeps jdk_ 卸载
#卸载完毕后可安装JDK
rpm -ivk rpm包
参考链接:
yum与python不兼容_weixin_30408675的博客-CSDN博客
redhat6.5配置yum源,经历多天,列举出遇到的各种问题并逐一解决!!!!_snow_f的博客-CSDN博客
Cannot retrieve repository metadata (repomd.xml) for repository: base.错误_healery93的博客-CSDN博客