文章借鉴于:Centos误删自带python2.7恢复方法_centos默认的被卸载了-CSDN博客
在进行别的操作的时候,一不小心将我的系统自带的Python2.7.5和yum删除掉了。
后来我尝试重新安装yum,但是安装yum必须要有python。
我又去重新安装了python,但是我一开始选择了安装3.8版本,所安装的yum又是需要python2版本的,所以还是不行。
最后通过网上找的一个办法,只需要在一个网站里将所有需要的包都下载安装下来就行了。下面我记录一下。
1 首先把残留的Python环境删除干净
bash
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
whereis python|xargs rm -frv
2 查看当前的系统版本
bash
cat /etc/redhat-release
3 使用wget下载所需要的python和yum的rpm包。(wget下载不下来的要去网站里获取正确的路径,或者选择手动下载下来再上传到服务器中)
资源网站:Index of /
将版本号设置成为你的,我的系统的当前版本号是
bash
mkdir /usr/local/src/python
cd /usr/local/src/python
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-2.7.5-76.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-devel-2.7.5-76.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-libs-2.7.5-76.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-urlgrabber-3.10-9.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-build-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-build-libs-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-libs-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-python-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/rpm-sign-4.11.3-35.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-aliases-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-50.el7.noarch.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
下载失败的要去资源网站中手动下载。
4 安装
最后进行安装。
bash
rpm -Uvh --replacepkgs lvm2-python-libs*.rpm --nodeps --force
rpm -Uvh --replacepkgs libxml2-python*.rpm --nodeps --force
rpm -Uvh --replacepkgs python*.rpm --nodeps --force
rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm --nodeps --force
安装的时候也一定要看看是不是有什么缺失的没有下载的包,记得去资源网站中下载下来。
5 测试
可以看到python和yum恢复成功。