坑-centOS7.2--》重装 python2.7和yum!(原因误删了python后,yum不能用了)

(原因误删了python后,yum不能用了),所以决定重装python和yum;

由于这个错误:

坑-centOS7.2--》重装 python2.7和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/

坑-centOS7.2--》重装 python2.7和yum!(原因误删了python后,yum不能用了)

由于我的时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

坑-centOS7.2--》重装 python2.7和yum!(原因误删了python后,yum不能用了)

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

当出现问题:

坑-centOS7.2--》重装 python2.7和yum!(原因误删了python后,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/寻找并安装缺少的依赖文件,即可。