问题描述
最近想要将服务器上的Python2.7升级成3.x的版本时。使用了如下命令:
1
2
3
4
5
|
(1)强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps (2)删除残余文件 # whereis python|xargs rm -frv |
执行命令后导致服务器上的yum命令和python命令都无法使用。出现以下报错:
1
2
3
4
5
|
[root@test ~]# python -V -bash: /usr/bin/python: No such file or directory [root@test ~]# yum -bash: /usr/bin/yum: No such file or directory |
解决方案
1.创建目录用来存放rpm包:
1
|
mkdir /usr/local/src/python |
查看系统版本:
1
|
lsb_release -a |
查看位数
1
|
getconf LONG_BIT |
2.进入目录,使用wget分别下载python以及yum的rpm包
http://vault.centos.org/ 这个地址可以下载不同版本系统对应的包(注意:一定要和系统的版本号对应)
可以看到我们的系统版本是7.5.1804,这里下载以下文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/lvm2-python-libs-2.02.177-4.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-libs-2.7.5-68.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-2.7.5-68.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/python-chardet-2.2.1-1.el7_1.noarch.rpm<br> wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/rpm-python-4.11.3-32.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-plugin-aliases-1.1.31-45.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-45.el7.noarch.rpm wget http: //vault.centos.org/7.5.1804/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm |
3.执行以下命令,开始安装
1
2
3
4
5
6
7
|
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 |
说明:--nodeps --force表示仅安装当前的,不考虑安装所需的依赖
4.测试python是否可用
python命令正常
5.测试yum是否可用
yum命令正常
至此centos7.5重新安装python2.7及yum完成。