Centos 6.10 reinstall python and yum

Delete all python versions##

rpm -qa|grep python|xargs rpm -e --allmatches --nodeps``whereis python|xargs rm -rf

[ root@centos6 ~]# rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
warning:    erase unlink of/usr/lib/python2.6/site-packages/pip/wheel.pyo failed: No such file or directory
warning:    erase unlink of/usr/lib/python2.6/site-packages/pip/wheel.pyc failed: No such file or directory
warning:    erase unlink of/usr/lib/python2.6/site-packages/pip/wheel.py failed: No such file or directory
warning:    erase unlink of/usr/lib/python2.6/site-packages/pip/vcs/subversion.pyo failed: No such file or directory
warning:    erase unlink of/usr/lib/python2.6/site-packages/pip/vcs/subversion.pyc failed: No such file or directory

[ root@centos6 ~]# whereis python
python:/usr/bin/python3.6/usr/lib/python2.6/usr/lib64/python2.6[root@centos6 ~]# 
[ root@centos6 ~]# whereis python|xargs rm -fr
[ root@centos6 ~]# 
[ root@centos6 ~]# whereis python
python:[root@centos6 ~]# 

Check if you can still use python

[ root@centos6 ~]# python
- bash:/usr/bin/python: No such file or directory
[ root@centos6 ~]# 
[ root@centos6 ~]# python3
- bash: python3: command not found
[ root@centos6 ~]# 
[ root@centos6 ~]# python3.6-bash: python3.6: command not found
[ root@centos6 ~]# 
[ root@centos6 ~]# 

Uninstall yum

rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps``rm -rf /etc/yum.repos.d/*``whereis yum | xargs rm -rf

[ root@centos6 ~]# rpm -qa|grep yum
PackageKit-yum-plugin-0.5.8-26.el6.x86_64
yum-utils-1.1.30-41.el6.noarch
PackageKit-yum-0.5.8-26.el6.x86_64
yum-plugin-fastestmirror-1.1.30-41.el6.noarch
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-3.2.29-81.el6.centos.noarch
yum-plugin-security-1.1.30-41.el6.noarch
[ root@centos6 ~]# 
[ root@centos6 ~]# rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
[ root@centos6 ~]# rm -rf /etc/yum.repos.d/*
[ root@centos6 ~]# 
[ root@centos6 ~]# whereis yum
yum: /etc/yum
[ root@centos6 ~]# 
[ root@centos6 ~]# whereis yum | xargs rm -rf 
[ root@centos6 ~]# 
[ root@centos6 ~]# whereis yum
yum:
[ root@centos6 ~]# 

View the system version number##

[ root@centos6 ~]# cat /etc/issue
CentOS release 6.10(Final)
Kernel \r on an \m

[ root@centos6 ~]# 

Follow-up to find the mirror download according to the system version number.

Find the package download of Centos6 system mirror##

First search Centos to find the mirror download, and then find the mirror library from the mirror download.

These are all mirror libraries, find the correct version of your system to download.

Set the path /centos/6.10/os/x86_64/Packages/ after the mirror url to find the address of the mirror library, as follows:

Install python

Create the python installation directory:

[ root@centos6 ~]# mkdir -p /usr/local/src/python

Download the installation file:

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
 
wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
 
wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-pycurl-7.19.0-9.el6.x86_64.rpm
 
wget  http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-devel-2.6.6-66.el6_8.x86_64.rpm
 
wget  http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-libs-2.6.6-66.el6_8.x86_64.rpm
 
wget  http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
 
wget  http://mirrors.163.com/centos/6.10/os/x86_64/Packages/rpm-python-4.8.0-59.el6.x86_64.rpm

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/python-setuptools-0.6.10-4.el6_9.noarch.rpm

The rpm file after downloading:

[ root@centos6 python]# ls
python-2.6.6-66.el6_8.x86_64.rpm        python-iniparse-0.3.1-2.1.el6.noarch.rpm  python-pycurl-7.19.0-9.el6.x86_64.rpm      rpm-python-4.8.0-59.el6.x86_64.rpm
python-devel-2.6.6-66.el6_8.x86_64.rpm  python-libs-2.6.6-66.el6_8.x86_64.rpm     python-urlgrabber-3.9.1-11.el6.noarch.rpm
[ root@centos6 python]# 

Perform the installation:
rpm -ivh python-* rpm-python-*

[ root@centos6 python]# rpm -ivh python-*   rpm-python-*
Preparing...                ########################################### [100%]package python-libs-2.6.6-66.el6_8.x86_64 is already installed
 package python-2.6.6-66.el6_8.x86_64 is already installed
 package python-pycurl-7.19.0-9.el6.x86_64 is already installed
 package python-urlgrabber-3.9.1-11.el6.noarch is already installed
 package python-devel-2.6.6-66.el6_8.x86_64 is already installed
 package python-iniparse-0.3.1-2.1.el6.noarch is already installed
[ root@centos6 python]# 
[ root@centos6 python]# python
Python 2.6.6(r266:84292, Aug 182016,15:13:37)[GCC 4.4.720120313(Red Hat 4.4.7-17)] on linux2
Type "help","copyright","credits" or "license"for more information.>>>exit()

Install yum

Create yum installation directory:

mkdir -p /usr/local/src/yum

Find the path of the rpm package to be downloaded:

[ root@centos6 yum]# curl http://mirrors.163.com/centos/6.10/os/x86_64/Packages/>1.txt
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
         Dload  Upload   Total   Spent    Left  Speed
100 859 k    0  859k    00   442k      0--:--:--0:00:01--:--:--  451k
[ root@centos6 yum]# ls
1. txt
[ root@centos6 yum]# vim 1.txt 
[ root@centos6 yum]# 
[ root@centos6 yum]# cat 1.txt | grep yum | grep centos.noarch.rpm
< a href="kabi-yum-plugins-1.0-2.el6.centos.noarch.rpm">kabi-yum-plugins-1.0-2.el6.centos.noarch.rpm</a>07-Jul-201118:577724<a href="yum-3.2.29-81.el6.centos.noarch.rpm">yum-3.2.29-81.el6.centos.noarch.rpm</a>23-Mar-201723:04   1018K
< a href="yum-cron-3.2.29-81.el6.centos.noarch.rpm">yum-cron-3.2.29-81.el6.centos.noarch.rpm</a>23-Mar-201722:59     46K
[ root@centos6 yum]# 
[ root@centos6 yum]# cat 1.txt | grep yum | grep yum-metadata-parser
< a href="yum-metadata-parser-1.1.2-16.el6.x86_64.rpm">yum-metadata-parser-1.1.2-16.el6.x86_64.rpm</a>26-Sep-201112:25     27K
[ root@centos6 yum]# 
[ root@centos6 yum]# cat 1.txt | grep yum | grep yum-plugin-fastestmirror
< a href="yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm">yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm</a>20-Jun-201819:43     33K
[ root@centos6 yum]# 

Download the installation file:

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
 
wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
 
wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-utils-1.1.30-41.el6.noarch.rpm

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-plugin-protectbase-1.1.30-41.el6.noarch.rpm

wget http://mirrors.163.com/centos/6.10/os/x86_64/Packages/yum-plugin-aliases-1.1.30-41.el6.noarch.rpm

Downloaded rpm package

[ root@centos6 yum]# ls
1. txt                                        yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
yum-3.2.29-81.el6.centos.noarch.rpm          yum-plugin-protectbase-1.1.30-41.el6.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm  yum-utils-1.1.30-41.el6.noarch.rpm
yum-plugin-aliases-1.1.30-41.el6.noarch.rpm
[ root@centos6 yum]# 

Install the rpm package

[ root@centos6 yum]# rpm -ivh yum-*--force --nodeps
Preparing...                ########################################### [100%]1:yum-metadata-parser    ########################################### [17%]2:yum-plugin-fastestmirro########################################### [33%]3:yum                    ########################################### [50%]4:yum-utils              ########################################### [67%]5:yum-plugin-aliases     ########################################### [83%]6:yum-plugin-protectbase ########################################### [100%][root@centos6 yum]# 

Execute yum

[ root@centos6 yum]# yum 
Loaded plugins: aliases, fastestmirror, protectbase
You need to give some command
Usage: yum [options] COMMAND

List of Commands:

alias          Adds or lists aliases
check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade      downgrade a package[root@centos6 yum]# ls /etc/yum.repos.d/[root@centos6 yum]# 

You can see that the yum source files of Centos6 have been deleted and need to be retrieved.

Set up CentOS-Base.repo

[ root@centos6 yum.repos.d]# cat CentOS-Base.repo 
[ base]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
 http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-6
 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6[updates]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
 http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-6
 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6[extras]
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
 http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cloud.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-6
 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6[root@centos6 yum.repos.d]# 

Set epel.repo

[ root@centos6 yum.repos.d]# cat epel.repo 
[ epel]
name=Extra Packages for Enterprise Linux 6- $basearch
enabled=1
failovermethod=priority
baseurl=http://mirrors.cloud.aliyuncs.com/epel/6/$basearch
 http://mirrors.aliyun.com/epel/6/$basearch
gpgcheck=0
gpgkey=http://mirrors.cloud.aliyuncs.com/epel/RPM-GPG-KEY-EPEL-6
 http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-6[root@centos6 yum.repos.d]# 

Finally, set up yum cache##

[ root@centos6 yum.repos.d]# yum makecache
Loaded plugins: aliases, fastestmirror, protectbase
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                  |3.7 kB     00:00     
epel                                                                                  |4.7 kB     00:00     
epel/filelists_db                                                                     |7.9 MB     00:00     
epel/updateinfo                                                                       |817 kB     00:00     
epel/prestodelta                                                                      |1.3 kB     00:00     
epel/other_db                                                                         |3.0 MB     00:00     
extras                                                                                |3.4 kB     00:00     
extras/prestodelta                                                                    |2.2 kB     00:00     
extras/other_db                                                                       |14 kB     00:00     
updates                                                                               |3.4 kB     00:00     
updates/filelists_db                                                                  |3.0 MB     00:00     
updates/prestodelta                                                                   |153 kB     00:00     
updates/other_db                                                                      |213 kB     00:00     
Metadata Cache Created
[ root@centos6 yum.repos.d]# 

Test installation:

[ root@centos6 yum.repos.d]# yum install -y tree
Loaded plugins: aliases, fastestmirror, protectbase
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
0 packages excluded due to repository protections
Resolving Dependencies
- - > Running transaction check
- - - > Package tree.x86_64 0:1.5.3-3.el6 will be installed
- - > Finished Dependency Resolution

Okay, yum is installed here. If there are other files, you can refer to the following document, which is also very good.

Solve the error when running yum: No module named rpm

Check whether the python pointed to by yum is 2.6.6

[ root@centos6 python]# head -1/usr/bin/yum
#! /usr/bin/python
[ root@centos6 python]# 
[ root@centos6 python]# head -1/usr/bin/yum
#! /usr/bin/python
[ root@centos6 python]# /usr/bin/python --version
Python 2.6.6[root@centos6 python]# 

Recommended Posts

Centos 6.10 reinstall python and yum
centos7 install python3 and ipython
CentOS7 install python3 and pip3
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
CentOS + Python3.6+
Centos 7.5 python3.6
CentOS7 yum install and start mysql
CentOS quickly install Python3 and pip3
CentOS7 yum install and start mysql
Install Python3 and ansible under CentOS8
Configure python3 environment on centos7 and
Install Python3 and Py under CentOS7
CentOS7 repairs python to save yum
Centos6 install Python2.7.13
Centos7 install Python 3.6.
CentOS7 upgrade python3
CentOS install Python 3.6
Python - centos6 installation
Centos7 install Python2.7
Python and Go
Centos python3 compile installation and compile gcc upgrade
Python and scrapy deployment in centos environment
Centos install Python3
Compile and install nodejs and yum in Centos8
CentOS6.8 install python2.7
Install svn and configuration through yum under CentOS
Install centos7 and connect
Python introspection and reflection
Centos 6.4 python 2.6 upgrade to 2.7
Vmware-install and start Centos 8
Centos 6.4 python 2.6 upgrade to 2.7
Vmware-install and start Centos 7
CentOS server deployment (YUM)
Centos source installation Python3
[python] python2 and python3 under ubuntu
CentOS 7.2 Yum install MySQL 5.6
Centos7 YUM install MariaDB 10.0
Python deconstruction and packaging
Python3 configuration and entry.md
CentOS 5 to CentOS 5.8 YUM source
CentOS Python Java installations
CentOS comes with Python deleted &amp;&amp; YUM error repair
Python automated operation and maintenance 2
Centos default python2.6 upgrade to
Python introduction and environment installation
CentOS upgrade python2 to pyth
Python know crawler and anti crawler
Centos mysql installation and configuration
Know Linux and install CentOS
centos install mysql through yum
CentOS 7 install Mono and MonoDevelop
Centos7 installation and configuration prometheus
ubuntu18.04 compile and install python3.8
CentOS6.5 install Java 8 and Tomcat8
CentOS 7 installation and configuration PPTP
Centos compile and install Git
Python open read and write
CentOS installation and configuration cmake
Basic usage and examples of yum under Liunx (centos8) (recommended)
Centos7.5 installation and configuration MongoDB4.0.4