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
...
...

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM