删除所有python版本
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 ~]#
检查还能否使用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 ~]#
卸载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 ~]#
查看系统版本号
[root@centos6 ~]# cat /etc/issue
CentOS release 6.10 (Final)
Kernel \r on an \m
[root@centos6 ~]#
后续根据系统版本号去找镜像下载。
寻找Centos6系统镜像的包下载
在任何一个镜像站中找到你系统对应版本的python rpm包(我的是centos 6.10的64位系统,使用的镜像是http://mirrors.163.com/centos/6.10/os/x86_64/Packages/)
首先搜索Centos就可以找到镜像的下载,再从镜像下载寻找镜像库即可。
这些都是镜像库,找对自己系统的版本来下载。
在镜像的url后面设置路径/centos/6.10/os/x86_64/Packages/
就可以找到镜像库的地址了,如下:
安装python
创建python的安装目录:
[root@centos6 ~]# mkdir -p /usr/local/src/python
下载安装文件:
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
下载完毕后的rpm文件:
[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]#
执行安装:
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 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
安装yum
创建yum的安装目录:
mkdir -p /usr/local/src/yum
寻找需要下载的rpm包路径:
[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 859k 0 859k 0 0 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
kabi-yum-plugins-1.0-2.el6.centos.noarch.rpm 07-Jul-2011 18:57 7724
yum-3.2.29-81.el6.centos.noarch.rpm 23-Mar-2017 23:04 1018K
yum-cron-3.2.29-81.el6.centos.noarch.rpm 23-Mar-2017 22:59 46K
[root@centos6 yum]#
[root@centos6 yum]# cat 1.txt | grep yum | grep yum-metadata-parser
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm 26-Sep-2011 12:25 27K
[root@centos6 yum]#
[root@centos6 yum]# cat 1.txt | grep yum | grep yum-plugin-fastestmirror
yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm 20-Jun-2018 19:43 33K
[root@centos6 yum]#
下载安装文件:
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
下载完毕的rpm包
[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]#
安装rpm包
[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]#
执行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]#
可以看到Centos6的yum源文件都被删除了,需要重新找回来。
设置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]#
设置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]#
最后设置一下yum缓存
[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]#
测试安装:
[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
好了,到这里就安装完毕yum了,如果还有其他文件的话,可以参考下面的这个文献,也是很不错的。
解决运行yum报错:No module named rpm
参考文献
查看yum指向的python是否为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]#