CentOS系统不小心卸载python2导致yum不可用

背景:

  项目使用的是python3,在安装python3时出现各种问题。所以直接将系统的python2和python3全部卸载了,

导致yum命令无效,因为yum是依赖python2的,所以还是乖乖装上python2吧

步骤:

1、检查python2是否卸载干净

#卸载python
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps 
##删除所有残余文件
whereis python |xargs rm -frv   
##验证删除,返回无结果
whereis python

2、删除yum

#删除yum
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps 
#删除残留文件
whereis yum |xargs rm -frv 
#验证删除完成,返回无结果
whereis yum

3、查看Linux版本,确定需要安装的python包

# 命令
[root@vm054sit005 ~]# cat /etc/redhat-release
#版本号
CentOS Linux release 7.9.2009 (Core)

4、在官网或者其他镜像网站(推荐,速度快)下载对应的包

从下面下载相应的包

清华镜像(推荐):https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/ 

网易镜像:https://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/

官方:http://vault.centos.org/7.9.2009/os/x86_64/Packages/

注意路径中的系统版本号

直接安装 python2.7.5和yum

# 安装python2.7.5

rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm

# 安装yum

rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh  --nodeps https://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

5、验证python、yum

# 验证python
[root@vm054sit005 ~]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

验证yum

[root@vm054sit005 ~]#yum
Loaded plugins: fastestmirror
You need to give some command
Usage: yum [options] COMMAND
...
...

 

posted @ 2022-02-22 10:56  秋寻草  阅读(1525)  评论(1编辑  收藏  举报