安装 yum

yum 安装本来是个很简单的事情,只是网上的教程一般不全,每次装每次都踩坑,必须做个笔记了。

具体安装过程请自行百度,一堆,耐心点就好。

 

异常记录

1. 明明按教程一步步安装完了,仍然报错

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.12 (default, Oct  1 2019, 01:09:22) 
[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 依赖 自带的 python,所以更新版本之后要把 yum 的配置改回老版本。

 

此时最简单的办法是 切到 python2 的环境下进行安装,linux 默认是 python2,在虚拟环境中会安装 python3,退出虚拟环境即可,此外还有另外一种解决方法,见下文

 

解决办法

第一步: 查看 python 版本

[root@hadoop10 yum]# whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz

我 重装了 python,把 2.6 升级到了 2.7

 

第二步:修改 yum 的 python 版本

[root@hadoop10 yum]# which yum
/usr/bin/yum
[root@hadoop10 yum]# vi /usr/bin/yum

#!/usr/bin/python2.6
import sys
try:
    import yum
except ImportError:

把 yum 第一行 python 改成 python2.6

 

报这种错误解决方法同上,修改 /usr/libexec/urlgrabber-ext-down

Downloading packages:
  File "/usr/libexec/urlgrabber-ext-down", line 28
    except OSError, e:
                  ^
SyntaxError: invalid syntax

 

2. 报错如下

[root@hadoop10 site-packages]# yum makecache
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Determining fastest mirrors
http://mirrors.163.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.163.com'"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

解决办法

[root@hadoop10 site-packages]# cd /etc/yum.repos.d/
[root@hadoop10 yum.repos.d]# ls
CentOS-Base-163.repo  CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
[root@hadoop10 yum.repos.d]# vi CentOS-Base.repo 

把 所有的 $releasever 换成 6

 

yum 源 安装软件

Centos 7版本已经于2024/6/30结束了官方支持,当系统尝试使用已经停止支持的软件仓库时,yum源 无法为软件集合仓库找到有效的基础URL。。

解决办法

cd /etc/yum.repos.d/
mv CentOS-SCLo-scl.repo CentOS-SCLo-scl.repo.bak
mv CentOS-SCLo-scl-rh.repo CentOS-SCLo-scl-rh.repo.bak


# vim CentOS-SCLo-rh.repo
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

 

 

 

 

参考资料:

https://blog.csdn.net/yqj234/article/details/83374665  安装

http://www.mamicode.com/info-detail-2392307.html  安装

http://blog.chinaunix.net/uid-9881170-id-5749784.html    异常 2

https://blog.csdn.net/u013615806/article/details/51043898  异常 2

 

centos 7 更换为阿里云yum源 - 认真的韩工 - 博客园