1. 程式人生 > >CentOS7重新安裝python、yum

CentOS7重新安裝python、yum

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

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
>>>

如上,要是什麼都沒報,則問題解決