Skip to main content
  1. Errors/

Centos7: 误删python2导致yum无法使用

219 words·2 mins
Linux
Table of Contents

uninstall python
#

优先卸载,确保环境干净

rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps 
whereis python |xargs rm -frv   
whereis python

delete yum
#

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps 
whereis yum |xargs rm -frv 
whereis yum

View system version
#

cat /etc/redhat-release

# CentOS Linux release 7.9.2009 (Core)

Download the corresponding package from the official website or other mirror sites (recommended, fast)

install python

rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-devel-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-libs-2.7.5-89.el7.x86_64.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/rpm-python-4.11.3-45.el7.x86_64.rpm

install yum

rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh  --nodeps http://vault.centos.org/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

There are no enabled repos.Run “yum repolist all
#

yum repolist all

如果没有安装任何源,说明没有配置

mkdir  /etc/yum/repos.d/

编辑/etc/yum/repos.d/fedora-163.repo

# vim /etc/yum/repos.d/fedora-163.repo
[fedora]
 
name=Fedora 17 - $basearch - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/$basearch/os/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-17&arch=$basearch
enabled=1
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[fedora-debuginfo]
name=Fedora 17 - $basearch - Debug - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-debug-17&arch=$basearch
enabled=0
metadata_expire=7d 
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[fedora-source]
name=Fedora 17 - Source - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/releases/17/Everything/source/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-source-17&arch=$basearch
enabled=0
metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

编辑vim /etc/yum/repos.d/fedora-updates-163.repo

[updates]
name=Fedora 17 - $basearch - Updates - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/$basearch/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f17&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[updates-debuginfo]
name=Fedora 17 - $basearch - Updates - Debug - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/$basearch/debug/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f17&arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
 
[updates-source]
name=Fedora 17 - Updates Source - 163.com
failovermethod=priority
baseurl=http://mirrors.163.com/fedora/updates/17/SRPMS/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f17&arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

安装

yum makecache

Related

Centos7 换源&更新网络连接
151 words·1 min
Linux
Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64 # reset /etc/yum.
Linux upgrade gcc g++
115 words·1 min
Linux
Ubuntu gcc 升降级 # 更新系统包
Centos8: Errors during downloading metadata for repository 'base'
87 words·1 min
Linux
Errors during downloading metadata for repository ‘base‘ # CentOS-8 - Base - mirrors.
Upgrade openssh version 9.0 on centos7
200 words·1 min
Linux
Upgrade OpenSSH to 9.
Linux 基础配置及命令行操作
585 words·3 mins
Linux
免密登录配置 # 生成公钥、私钥