前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos 6.10重装python和yum

Centos 6.10重装python和yum

作者头像
Devops海洋的渔夫
发布2019-05-30 21:52:40
1.6K0
发布2019-05-30 21:52:40
举报
文章被收录于专栏:Devops专栏Devops专栏

删除所有python版本

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

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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 ~]# 

查看系统版本号

代码语言:javascript
复制
[root@centos6 ~]# cat /etc/issue
CentOS release 6.10 (Final)
Kernel \r on an \m

[root@centos6 ~]# 

后续根据系统版本号去找镜像下载。

寻找Centos6系统镜像的包下载

首先搜索Centos就可以找到镜像的下载,再从镜像下载寻找镜像库即可。

这些都是镜像库,找对自己系统的版本来下载。

在镜像的url后面设置路径/centos/6.10/os/x86_64/Packages/就可以找到镜像库的地址了,如下:

安装python

创建python的安装目录:

代码语言:javascript
复制
[root@centos6 ~]# mkdir -p /usr/local/src/python

下载安装文件:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
[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-*

代码语言:javascript
复制
[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的安装目录:

代码语言:javascript
复制
mkdir -p /usr/local/src/yum

寻找需要下载的rpm包路径:

代码语言:javascript
复制
[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
<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-2011 18:57    7724
<a href="yum-3.2.29-81.el6.centos.noarch.rpm">yum-3.2.29-81.el6.centos.noarch.rpm</a>                23-Mar-2017 23: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-2017 22: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-2011 12: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-2018 19:43     33K
[root@centos6 yum]# 

下载安装文件:

代码语言:javascript
复制
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包

代码语言:javascript
复制
[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包

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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缓存

代码语言:javascript
复制
[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]# 

测试安装:

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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]# 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 删除所有python版本
  • 卸载yum
  • 查看系统版本号
  • 寻找Centos6系统镜像的包下载
  • 安装python
  • 安装yum
  • 设置CentOS-Base.repo
  • 设置epel.repo
  • 最后设置一下yum缓存
  • 解决运行yum报错:No module named rpm
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档