前些天手贱不小心把centos 6.9 里面的python2都删除了,导致yum因为缺少python环境而不能用,具体报错大概是这样:
-bash: /usr/bin/yum: /usr/bin/python2: bad interpreter: No such file or directory
在网上搜了很多不太靠谱的教程之后,自己总结一下
首先是把python和yum的rpm包下载下来,网上很多教程都是网易的镜像什么的,比如http://mirrors.163.com/centos/6.9/os/x86_64/Packages/ 这个文件夹早就没有啦!只有一个readme,好了那我直接上去他readme里面的网址里面找就好了
所以最后的镜像网址是http://vault.centos.org/
好了说了很多废话,其实我把全部命令都整理好了,直接复制就可以了
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-dateutil-1.4.1-7.el6.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-devel-2.6.6-66.el6_8.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-libs-2.6.6-66.el6_8.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-pycurl-7.19.0-9.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-setuptools-0.6.10-3.el6.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-six-1.9.0-2.el6.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/rpm-python-4.8.0-55.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/rpm-build-4.8.0-55.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/rpm-libs-4.8.0-55.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/rpm-python-4.8.0-55.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
如果不是6.9版本的,把网址里面的6.9换成自己的就可以了,如果不知道自己的是多少,可以执行cat /etc/issue 看一看
如果嫌太多太麻烦,其实可以先复制到word文档里面,然后全部替换就好啦。嗯,做懒人真好,一直懒一直爽
最后划重点!!一定要rpm包一起安装,命令是
rpm -ivh python-*.rpm
rpm -ivh rpm-*.rpm
rpm -ivh yum-*.rpm
最后就大功告成了!快点输出yum看看吧
什么?还不行?
好吧,其实我也有报错啦
运行rpm -ivh rpm-*.rpm的时候报
意思就是说我缺了4个包,缺什么补什么嘛,人家都告诉你了缺什么了,那就继续下载,4个包的下载地址是
wget http://vault.centos.org/6.9/os/x86_64/Packages/gdb-7.2-92.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/patch-2.6-6.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/elfutils-0.164-2.el6.x86_64.rpm
wget http://vault.centos.org/6.9/os/x86_64/Packages/redhat-rpm-config-9.0.3-51.el6.centos.noarch.rpm
然后就是逐个安装啦,安装完之后再次运行rpm -ivh rpm-*.rpm, 完美!
运行rpm -ivh yum-*.rpm的时候,明明有3个包却只安装了一个,报错
原因是另外两个是互相依赖,那就简单啦,两个同时安装就好了
rpm -ivh yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
好了完美!
最后再yum试试呀