CentOS 7/8误删python导致yum不可用的解决办法
一、前言
博主Centos系统为Centos8.5.2111版本,可能当时脑抽就以为自己的系统是Centos7版本,安装一个包怎么装不上,网上查阅资料各种折腾,发现yum被我搞坏了,最后又是各种折腾安装yum,特意记录下来。
二、解决办法
卸载和删除python、yum的残留文件,再下载自己系统版本对应的python、yum包进行安装。
三、具体步骤
删除python已安装程序及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
删除残余python文件
whereis python |xargs rm -frv
验证删除,返回为无结果
whereis python
删除现有yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
删除残余yum文件
whereis yum |xargs rm -frv
查看系统信息
lsb_release -a
Release:8.5.2111 为我自己的Centos版本,下载的包的版本应与系统版本号对应的一致。
下载镜像网址
华为镜像站
https://repo.huaweicloud.com/centos/
Centos7 RPM包路径
https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/
Centos8 RPM包路径(Centos8已经停止维护,去centos/8-stream下面找BaseOS文件夹自己替换路径)
https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/
更改系统版本号为你自己的版本号
创建目录python和yum用以存放rpm包
mkdir /usr/local/src/python
mkdir /usr/local/src/yum
下载python以及yum的rpm包
centos7(由于版本升级一些链接404错误,请自行查找对应的rpm包):
#python
cd /usr/local/src/python
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-devel-2.7.5-88.el7.x86_64.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-88.el7.x86_64.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-43.el7.x86_64.rpm
#yum
cd /usr/local/src/yum
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://repo.huaweicloud.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
centos8(由于版本升级一些链接404错误,请自行查找对应的rpm包):
#python
cd /usr/local/src/python
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-asn1crypto-0.24.0-3.el8.noarch.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-dnf-4.7.0-4.el8.noarch.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-gpg-1.13.1-9.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-hawkey-0.63.0-3.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-libcomps-0.1.16-2.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-libdnf-0.63.0-3.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-libs-3.6.8-41.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/python3-rpm-4.14.3-19.el8.x86_64.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/platform-python-3.6.8-41.el8.x86_64.rpm
#yum
cd /usr/local/src/yum
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/yum-4.7.0-4.el8.noarch.rpm
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/yum-utils-4.0.21-3.el8.noarch.rpm
安装python以及yum的rpm包
#安装Python
cd /usr/local/src/python
#Centos7
rpm -ivh python-* rpm-python-* --nodeps --force
#Centos8
rpm -ivh python3-* platform-python-* --nodeps --force
#安装yum
cd /usr/local/src/yum
rpm -ivh yum-*
大功告成!
没有成功的查看以下方法
(来自:Wei.的方法,主页:https://iox7.com/user/131)
#安装yum-utils依赖
mkdir /usr/local/src/yum
cd /usr/local/src/yum
wget https://repo.huaweicloud.com/centos/8.5.2111/BaseOS/x86_64/os/Packages/yum-utils-4.0.21-3.el8.noarch.rpm
rpm -ivh yum-*
#下载全量依赖包
repotrack yum
#安装
rpm -Uvh --force --nodeps *.rpm
四、附件
Centos 8.5.2111 yum的全量依赖包:Centos8系统直接下载以下包执行 rpm -Uvh --force --nodeps *.rpm 安装即可。
下载地址:
提取码:yvuz
--来自百度网盘超级会员V5的分享