参考链接:
centos7 安装python2.6,与系统自带的python2.7共存
centos6.10 重新安装python2.6 和 yum (不可以直接安装yum yum 依赖于python2.6)
python升级导致yum命令无法使用的解决办法(修改版)
centos下RPM包的安装、卸载和查询
CentOS7.5误删python2.7及yum后解决办法(完全重新安装)
系统环境:
Centos 7.6.1810
Python环境:
Python 2.7.5
在此之前,我把python重新安装了一次。我安装的是python2.7.5。
1、卸载yum
- 强制删除系统安装程序yum包及其相关
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
- 删除所有残余文件
whereis yum |xargs rm -frv ##xargs,允许你对输出执行其他某些命令
- 验证删除
whereis yum ##验证删除,返回无结果
2、下载文件,重新安装
- 下载python和yum及其的依赖。根据自己具体系统和Python环境下载。我用的163的资源。163链接:
http://mirrors.163.com/centos/
先下载python的依赖。
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/python-libsss_nss_idmap-1.16.2-13.el7.x86_64.rpm
再下载yum及其依赖
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://mirrors.163.com/centos/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
- 安装依赖
先安装python依赖
rpm -ivh python*
再安装yum及其依赖
rpm -ivh yum*
本以为成功了,结果还是出现了No module named yum的问题。我很好奇。我就想重新安装了python,结果如下图
此时,我觉得可能是安装环节错了。所以想完全卸载python的依赖。如下图:
这就很奇怪了,安装时说已经安装好了,卸载时说没有安装。然后我就去百度rpm的命令。找到了强制升级的命令。结果如下图:
rpm -Uvh --force python* #--force为强行升级,--oldpackage为降级
3、测试
yum install vim
因为我之前已经安装了,所以是图片这个样子。总之,应该没有问题了。