Centos 7、Redhat7 重新安装python、yum(转)

来源于https://blog.csdn.net/chengpeng1996/article/details/81216230
1、删除现有Python

# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联

# whereis python |xargs rm -frv -rf ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令

# whereis python ##验证删除,返回无结果

2、删除现有的yum

# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

# whereis yum |xargs rm -frv -rf

3、从http://mirrors.163.com/centos/7/os/x86_64/Packages/下相应的包

python-2.7.5-68.el7.x86_64.rpm

python-devel-2.7.5-68.el7.x86_64.rpm

python-iniparse-0.4-9.el7.noarch.rpm

python-libs-2.7.5-68.el7.x86_64.rpm

python-pycurl-7.19.0-19.el7.x86_64.rpm

python-setuptools-0.9.8-7.el7.noarch.rpm

python-urlgrabber-3.10-8.el7.noarch.rpm

rpm-python-4.11.3-32.el7.x86_64.rpm

yum-3.4.3-158.el7.centos.noarch.rpm

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

yum-plugin-aliases-1.1.31-45.el7.noarch.rpm

yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm

yum-plugin-protectbase-1.1.31-45.el7.noarch.rpm

yum-utils-1.1.31-45.el7.noarch.rpm

由于源中版本会更新,下载时具体请查看版本再下载下来!

4、修改文件名:

# mv python-setuptools-0.9.8-7.el7.noarch.rpm python-setuptools-0.9.8-7.el7.noarch

# mv yum-utils-1.1.31-45.el7.noarch.rpm yum-utils-1.1.31-45.el7.noarch

# mv yum-plugin-aliases-1.1.31-45.el7.noarch.rpm yum-plugin-aliases-1.1.31-45.el7.noarch

5、进行安装

# rpm -Uvh --replacepkgs python*.rpm

# rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm

问题测试

# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
>>

问题解决

你可能感兴趣的:(Centos 7、Redhat7 重新安装python、yum(转))