(原因誤刪了python后,yum不能用了),所以決定重裝python和yum;
由於這個錯誤:
決定重裝一遍python和yum:
重裝別慌,不懂python和yum也別慌,網上的博客一抓一大把,根據自己的問題去尋找總能解決的。
卸載python:
#rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
#whereis python|xargs rm -fr
卸載yum:
#rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
#rm -rf /etc/yum.repos.d/*
#whereis yum|xargs rm -fr
在http://mirrors.ustc.edu.cn/centos/官網中的readme文件的提示信息:
This directory (and version of CentOS) is deprecated. For normal users,
you should use /7/ and not /7.5.1804/ in your path. Please see this FAQ
concerning the CentOS release scheme:
https://wiki.centos.org/FAQ/General
If you know what you are doing, and absolutely want to remain at the 7.5.1804
level, go to http://vault.centos.org/ for packages.
Please keep in mind that 7.5.1804 no longer gets any updates, nor
any security fix's.
決定去 http://vault.centos.org/這個網站找packages
1-首先,查看自己的centos版本;
cat /etc/redhat-release
根據自己版本去找 對應的依賴文件,os/x86_64/Packages/
由於我的時7.2.1511,所以去官網http://vault.centos.org/找到自己的7.2.1511版本下的/os/x86_64/Packages/
2-到官網復制python和yum的相關依賴文件,只能老老實實一個個對着找,慢,但是最穩當。
http://vault.centos.org/7.2.1511/os/x86_64/Packages/
新建文件夾放 python和yum文件:
#mkdir /usr/local/src/python
#mkdir /usr/local/src/yum
#cd /usr/local/src/python 進入目錄
python需要的:
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-devel-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm
#cd /usr/local/src/yum進入目錄
yum需要的:
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
3-安裝:
#cd /usr/local/src/python
#rpm -ivh python-* rpm-python-*
出現安裝包的依賴問題,此時如下解決即可:
#rpm -ivh python-* rpm-python-* --nodeps --force
--nodeps --force為不考慮依賴包,強制安裝。
安裝完后即可運行python
安裝yum:
#cd /usr/local/src/yum
#rpm -ivh yum-*
當出現問題:
說明是你的curl缺少安裝文件:
缺什么就補什么,去http://vault.centos.org/尋找的依賴文件,
新建文件夾:
#mkdir /usr/local/src/curl
#cd/usr/local/src/curl
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/curl-7.29.0-25.el7.centos.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/libcurl-7.29.0-25.el7.centos.x86_64.rpm
#rpm -ivh ./*
再試試yum,就成功了。
同理,如果你缺少的是其他的依賴文件,就去http://vault.centos.org/尋找並安裝缺少的依賴文件,即可。
如果發現你的yum install 失敗,是yum源資源出了問題,請參考下面這篇,更新centos系統的repo文件
https://www.cnblogs.com/mjbenkyo/p/12558095.html