-bash: yum: command not found

来源:互联网 发布:linux groupadd 编辑:程序博客网 时间:2024/05/22 02:10
不知道做啥操作了,yum命令-bash: yum: command not found报这个错误,然后网上搜了好多,发现这哥们写的不错,就试了一下还是不行,不过写的不错,先mark一个!

步骤如下
第一步:
       http://mirrors.163.com/centos/6/os/x86_64/Packages/
       到上面这个网站去下载如下RPM包
       python-iniparse-0.3.1-2.1.el6.noarch.rpm
       yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm 
       yum-3.2.29-69.el6.centos.noarch.rpm
       yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm
       下载完成之后,用rpm命令进行安装,如下:
        rpm -ivh --force --nodeps python-iniparse-0.3.1-2.1.el6.noarch.rpm
        rpm -ivh --force --nodeps yum-metadata-parser-1.1.2-14.1.el6.x86_64.rpm 
        rpm -ivh --force --nodeps  yum-3.2.29-69.el6.centos.noarch.rpm yum-plugin-fa
stestmirror-1.1.30-30.el6.noarch.rpm
        这里安装的时候需要注意,一定要加 --force --nodeps不然会报错安装不上
        到这一步了当你输入yum命令的时候出现如下错误:
        

第二步:
       根据上图的提示到 http://yum.baseurl.org/wiki
       下载yum-3.4.3.tar.gz ,放到你指定的目录下解压,解压命令如下:
        tar -zxvf yum-3.4.3.tar.gz     #解压后进到yum-3.4.3目录
        
        输入如下命令
        ./yummain.py update 如下图:
        

       注意红框中的操作,完成之后,你试着输入一下yum 就OK了,如下图:
       

如果上面的方法还不行,再试试这个哥们的~

最近在看python,虚拟机装的是Centos6.6,自带的python版本是2.6.6,打算升级到2.7。

我的升级过程大致如下:

  • 下载2.7源码包https://www.python.org/downloads/source/
  • 卸载旧的python,rpm -e python
  • 编译安装python2.7

整个过程没有遇到问题,但升级完后,再用yum安装软件时报如下错误

[root@localhost python]# yumThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:   No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:2.7.13 (r266:84292, Jan 22 2014, 09:37:14) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]If you cannot solve this problem yourself, please go to the yum faq at:  http://yum.baseurl.org/wiki/Faq

yum不可用了,这下问题就大了,spacer.gif没有yum,安装rpm包特别费劲。

开始百度关键字“No module named yum”,出来很多帖子和博客,博客上边说的大概意思就是yum就基于python的,升级python后,yum与高版本的python不兼容,导致yum无法使用。博客上给出的方法都是修改/usr/bin/yum文件的头部,把/usr/bin/python修改为/usr/bin/python2.6就可以了,但我的情况是我把旧的python已经卸载了,于是又开始安装2.6版本的python。

安装好2.6.6版本的之后以为就好了,但是还是报有错误:

[root@localhost python]# yumThere was a problem importing one of the Python modulesrequired to run yum. The error leading to this problem was:   No module named yumPlease install a package which provides this module, orverify that the module is installed correctly.It's possible that the above module doesn't match thecurrent version of Python, which is:2.6.6 (r266:84292, Jan 22 2014, 09:37:14) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]If you cannot solve this problem yourself, please go to the yum faq at:  http://yum.baseurl.org/wiki/Faq

这就奇怪了,都已经把旧版本的装上了,还是不行。这时看到一篇博客是把python和yum都全部卸载后重新安装的。想想这也是个办法于是就又全部下载

whereis python |xargs rm -rfrpm -e --nodeps python

卸载后重新安装,从光盘镜像里找到python和yum的包

rpm -ivh --nodeps python*rpm -ivh --nodeps yum*

这次总该好了吧,验证一下

[root@localhost python]# pythonPython 2.6.6 (r266:84292, Jan 22 2014, 09:37:14) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import yumTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 23, in <module>    import rpmImportError: No module named rpm

还是报错。。。

spacer.gif不过这次错误变了,变成了“No module named rpm”

再次百度,看到有人说是缺少包:rpm -ivh rpm-python-4.8.0-37.el6.i686.rpm

安装上面的包后一切yum恢复正常了。

那问题又来了难道因为yum就不升级python版本吗?当然不是。其实是我在安装新版python的时候把旧版本的也卸载了才导致这样的问题。

后来在不卸载2.6版本的python是,重新编译安装2.7版本,安装成功并且yum仍然可用。

反正上面几个哥们包括Stack Overflow找了一遍,我试了都不行,然后把其他机器的/usr/bin下面的ll python*文件拷过来,就搞定了~~