欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos7.6.1810 重装python与yum

程序员文章站 2022-04-04 17:08:49
...
可能你会在工作中、学习等过程中遇到服务器因为某些原因,从而导致需要安装或者重新安装pyton和yum的情况.但是网上各路鬼神说法各异甚至根本就无法执行等问题.Ok,不要着急,清晰的解决方案来了.好吧,我们进入正题.

第一步:卸载和清理
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps

whereis python |xargs rm -frv

rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps

whereis yum |xargs rm -frv

  ok,到这里为止呢已经清理完成.接下来就是下载安装包(注意:务必根据自己服务器的版本来下载依赖和包)!
第二步:下载安装包
查看server版本(我这里是 Centos 7.6.1810 )
cat /etc/redhat-release

首先,进入http://mirrors.ustc.edu.cn/centos/查找相对应的版本
我自己的server版本对应的路径为.这里我要提一下.很多童鞋们会在这里踩坑.centos7.0到centos7.8之前版本所有软件包,现在镜像站都将通用centos7版路径下的包.

官方是这样描述的:

This directory (and version of CentOS) is deprecated.  For normal users,
you should use /7/ and not /7.0.1406~7.7.1908/ in your path. Please see this FAQ
concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

If you know what you are doing, and absolutely want to remain at the 7.0.1406~7.7.1908
level, go to http://vault.centos.org/ for packages. 

Please keep in mind that 7.0.1406~7.7.1908 no longer gets any updates, nor
any security fix's.


,所以centos7路径地址:http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/



为了清晰和方便安装,先创建一个软件的安装目录
mkdir /opt/install


然后wget以下软件包(如果你网络不是很好,或者担心会断掉.可以加上断点续传):

wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/libxml2-python-2.9.1-6.el7.4.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-1.0-8.el7.x86_64.rpm  
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-chardet-2.2.1-3.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-devel-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-ipaddress-1.0.16-2.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-kitchen-1.1.1-5.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-libs-2.7.5-88.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-pycurl-7.19.0-19.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-setuptools-0.9.8-7.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/python-virtualenv-15.1.0-2.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-python-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/rpm-sign-4.11.3-43.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-aliases-1.1.31-53.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-plugin-protectbase-1.1.31-53.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm





第三步:安装

接下来,就是安装上面下载的软件

rpm -ivh --force --nodeps libxml2-python-2.9.1-6.el7.4.x86_64.rpm
rpm -ivh --force --nodeps python-2.7.5-88.el7.x86_64.rpm
rpm -ivh --force --nodeps python-backports-1.0-8.el7.x86_64.rpm  
rpm -ivh --force --nodeps python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm
rpm -ivh --force --nodeps python-chardet-2.2.1-3.el7.noarch.rpm
rpm -ivh --force --nodeps python-devel-2.7.5-88.el7.x86_64.rpm
rpm -ivh --force --nodeps python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh --force --nodeps python-ipaddress-1.0.16-2.el7.noarch.rpm
rpm -ivh --force --nodeps python-kitchen-1.1.1-5.el7.noarch.rpm
rpm -ivh --force --nodeps python-libs-2.7.5-88.el7.x86_64.rpm
rpm -ivh --force --nodeps python-pycurl-7.19.0-19.el7.x86_64.rpm
rpm -ivh --force --nodeps python-setuptools-0.9.8-7.el7.noarch.rpm
rpm -ivh --force --nodeps python-urlgrabber-3.10-10.el7.noarch.rpm
rpm -ivh --force --nodeps python-virtualenv-15.1.0-2.el7.noarch.rpm
rpm -ivh --force --nodeps rpm-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps rpm-build-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps rpm-build-libs-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps rpm-libs-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps rpm-python-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps rpm-sign-4.11.3-43.el7.x86_64.rpm
rpm -ivh --force --nodeps yum-3.4.3-167.el7.centos.noarch.rpm
rpm -ivh --force --nodeps yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh --force --nodeps yum-plugin-aliases-1.1.31-53.el7.noarch.rpm
rpm -ivh --force --nodeps yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
rpm -ivh --force --nodeps yum-plugin-protectbase-1.1.31-53.el7.noarch.rpm
rpm -ivh --force --nodeps yum-utils-1.1.31-53.el7.noarch.rpm



  Ok,到这里基本上就已经卸载和重装完成了.

第四步:更新
最后,我们来更新以下源数据.
yum clean all

yum makecache

yum --skip-broken update


是的,没错!现在你就可以输入
python -v
yum
查看相应版本信息了.到此,圆满完成!如果你喜欢的话,请持续关注vahoa.ma的ITeye.
相关标签: centos python