之前因为不小心删除了cetos下的yum和python。现在需要重新安装。网上搜索了一些方法,这里总结了一下。亲测有效
一、卸载(如果安装了,没安装直接看第二步)
1、删除现有的python
rpm -qa|grep python|xargs rpm -ev –allmatches –nodeps ##强制清除已安装的程序及其关联
whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
whereis python ##验证删除,返回无结果说明清除干净
2、删除现有的yum
rpm -qa|grep yum|xargs rpm -ev –allmatches –nodeps
whereis yum |xargs rm -frv
二、安装
1、检查CentOS 7版本
cat /etc/centos-release
2、在 https://vault.centos.org/ 上根据自己版本查找对应的目录
比如我的是:https://vault.centos.org/7.4.1708/os/x86_64/Packages/
3、下载相应的包
页面直接搜索下面的名字
python-2.7.5
python-iniparse
python-libs
python-pycurl
python-urlgrabber
rpm-python
yum-3.4.3
yum-metadata-parser
yum-plugin-fastestmirror
然后右键复制链接
在centos下 下载
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-2.7.5-58.el7.x86_64.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-libs-2.7.5-58.el7.x86_64.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/rpm-python-4.11.3-25.el7.x86_64.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://vault.centos.org/7.4.1708/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm
5、安装
全部下载完后,安装
rpm -Uvh --replacepkgs python*.rpm
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
三、验证
安装成功