此文参照https://www.cnblogs.com/wangjunjiehome/p/9239005.html,特别感谢。
1、删除现有Python
[root@test~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联
[root@test~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@test~]# whereis python ##验证删除,返回无结果
2、删除现有的yum
[root@test~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@test~]# whereis yum |xargs rm -frv
3、从http://mirrors.ustc.edu.cn/centos/ 或者 https://mirrors.aliyun.com/centos下载相应的包,这个时候要查看自己系统的版本,很重要cat /etc/redhat-release -- CentOS Linux release 7.7.1908 (Core)
4.创建目录python和和yum用以存放rpm包
#mkdir /usr/local/src/python
#mkdir /usr/local/src/yum
#cd /usr/local/src/python 进入目录
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-2.7.5-86.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-2.7.5-86.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-devel-2.7.5-86.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-libs-2.7.5-86.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/rpm-python-4.11.3-40.el7.x86_64.rpm
切换到yum目录:cd /usr/local/src/yum
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget ftp://mirrors.ustc.edu.cn/centos/7.7.1908/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
执行安装 :
rpm -ivh python-* rpm-python-* --nodeps --force
rpm -ivh yum-*