Centos7重装yum

tip:重装yum原因非Python2卸载原因,亲测有效+踩坑

查询原有yum

  • rpm -qa |grep yum

删除原有yum应用

  • rpm -aq|grep yum|xargs rpm -e –nodeps
  • rpm -qa |grep yum

查询原有yum配置

  • whereis yum
  • rm -fr /etc/yum

下载yum所有rpm包(阿里镜像维护,使用清华镜像)

此处需要4个包

wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm

安装

rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

注意:最后两个包要同时安装(相互之间存在依赖)

更新repo文件

安装yum-config-manager[非必须]

yum install -y yum-utils device-mapper-persistent-data lvm2

稳定 docker仓库

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


此时出现异常

[root@grasp-38-60 opt]# yum-config-manager --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
Traceback (most recent call last):
  File "/bin/yum-config-manager", line 6, in <module>
    import yum
ImportError: No module named yum
  • 解决:(问题是未找到默认Python版本)
    • vim /usr/bin/yum-config-manager
    • 修改 #!/usr/bin/python -tt#!/usr/bin/python2 -tt

所有完成,可以成功使用yum及相关工具

posted @ 2021-03-30 14:18  如果云吃糖  阅读(282)  评论(0编辑  收藏  举报