linux误删系统自带python2,导致yum不可用
一、报错信息
[root@localhost ~]# yum install -y httpd
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:
If you cannot solve this problem yourself, please go to the yum faq at:
二、卸载现有python2以及yum
首先卸载现有python [这里指的后面已安装的python2, 如果安装了python3 不需要删除]
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps #卸载python
whereis python |xargs rm -frv ##删除所有残余文件
whereis python ##验证删除,返回无结果
删除现有的yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps #删除yum
whereis yum |xargs rm -frv #删除残留文件
whereis yum #验证删除完成
三、重装python2以及yum
1. 查看自己的centos版本
cat /etc/redhat-release
## 我这里linux版本为centos7.3.1611
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
2. 根据自己的版本,在官网安装包库里找相关安装包并修改下面的url部分即可
注意:误删python2后,一定要根据自己linux版本,去官网找对应的python2以及yum版本,随便找个python2.x安装, 还是会有问题
### 安装python2
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-2.7.5-48.el7.x86_64.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-devel-2.7.5-48.el7.x86_64.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-libs-2.7.5-48.el7.x86_64.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/rpm-python-4.11.3-21.el7.x86_64.rpm
### 安装yum
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh --nodeps http://vault.centos.org/7.3.1611/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
3. 验证
### 查看python版本
[root@localhost ~]# python --version
Python 2.7.5
### 查看yum
[root@localhost ~]# yum
Loaded plugins: fastestmirror
You need to give some command
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
....