今天安装python3.5.0时不小心删除删除yum以及python包导致usr/bin/目录下找不到yum以及python包报错
1、#首先查看Linux版本
[root@localhost cg]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2、#卸载原有的python和yum
2.1、#卸载python:
$rpm -qa|grep python|xargs rpm -e --allmatches --nodeps
$whereis python|xargs rm -fr
2.2、#卸载yum:
$rpm -qa|grep yum|xargs rpm -e --allmatches --nodeps
$rm -rf /etc/yum.repos.d/*
$whereis yum|xargs rm -fr
3、#到官网复制python和yum的相关依赖文件,一个个对着找。
https://vault.centos.org/7.2.1511/os/x86_64/Packages/
4、#新建文件夹放 python和yum文件:
$mkdir /usr/local/src/python
$mkdir /usr/local/src/yum
5、#下载python依赖包和yum依赖包
# 进入目录
$cd /usr/local/src/python
python需要的:
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-pycurl-7.19.0-17.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-devel-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-libs-2.7.5-34.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/python-urlgrabber-3.10-7.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/rpm-python-4.11.3-17.el7.x86_64.rpm
#进入目录
$cd /usr/local/src/yum
yum需要的:
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
6、安装python和yum:
6.1、安装python
$cd /usr/local/src/python
$rpm -ivh python-* rpm-python-*
遇到问题:
[root@localhost python]# rpm -ivh python-* rpm-python-*
error: Failed dependencies:
rpm = 4.11.3-17.el7 is needed by rpm-python-4.11.3-17.el7.x86_64
解决方法:分开安装
$rpm -ivh python-*
rpm -ivh rpm-python-* 在安装包后面加两个参数--nodeps --force,其作用为不再分析包之间的依赖关系而直接安装
$rpm -ivh rpm-python-* --nodeps --force
安装成功后使用python
[root@localhost python]# python -V
Python 2.7.5
[root@localhost python]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
6.2、安装yum:
$cd /usr/local/src/yum
$rpm -ivh yum-*
安装其他:
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/curl-7.29.0-25.el7.centos.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/libcurl-7.29.0-25.el7.centos.x86_64.rpm
rpm -ivh curl* lib*
看下yum是否可使用
yum list
转载:
Linux(二十四):CentOS7.2误删除python,无法使用yum文件,需要重装 python2.7和yum!_fen_fen的博客-CSDN博客