yum故障最终解决办法.移魂版 bash:yum:command not found

以下脚本使用前请用dos2unix进行转码

centos系列可以不用转码

 

CentOS 6.4 rpm -aq|grep yum|xargs rpm -e --nodeps//此命令为卸载自带的yum

 

#总结本文的目的是由于我自己yum故障,在网上找了很多方法均不完全活着根本不能成功,故此总结于此,希望能对才入门的同学有所帮助;我也是才接触CENTOS不久

我会把我&&Linux的点点滴滴记录下来,希望能帮助

 

-------------------灵魂超越者--------------------------------

#!/bin/bash

PATH=~/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH


# Check if user is root

if [ $(id -u) != "0" ]; then

   echo "Error: You must be root to run this script"

   exit 1

fi


clear

echo "========================================================================="

echo "Replace Redhat Enterprise Yum to CentOS Yum and Repos,  Written by Licess"

echo "========================================================================="



# uninstall rhel yum

echo "Uninstall Rhel Yum......"

rpm -qa|grep yum|xargs rpm -e --nodeps

# delete old rpm

echo "Clean old cache......"

rm -rf python-iniparse-0.3.1-2.1.el6.noarch.rpm

rm -rf yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm


# change directory for download

echo "change directory for download......"

mkdir /root/tmp4yuan/

cd /root/tmp4yuan/



# download CentOS Yum

echo "Download Python-iniparse......"

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm


echo "Download yum-metadata-parse......"

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm


echo "Download yum......"

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-40.el6.centos.noarch.rpm


echo "Download yum fastmirror......"

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm


# install CentOS Yum

echo "Installing......"

rpm -ivh  python-iniparse-0.3.1-2.1.el6.noarch.rpm

rpm -ivh  yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm


# replace repos

rm -rf /etc/yum.repos.d/CentOS-Base.repo

echo "[base]

name=CentOS-6.4 - Base - 163.com

baseurl=http://mirrors.163.com/centos/6.4/os/x86_64/

#mirrorlist=http://mirrors.163.com/?release=6.4&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6


#released updates

[updates]

name=CentOS-6.4 - Updates - 163.com

baseurl=http://mirrors.163.com/centos/6.4/updates/x86_64/

#mirrorlist=http://mirrors.163.com/?release=6.4&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6


#additional packages that may be useful

[extras]

name=CentOS-6.4 - Extras - 163.com

baseurl=http://mirrors.163.com/centos/6.4/extras/x86_64/

#mirrorlist=http://mirrors.163.com/?release=6.4&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6


#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-6.4 - Plus - 163.com

baseurl=http://mirrors.163.com/centos/6.4/centosplus/x86_64/

#mirrorlist=http://mirrors.163.com/?release=6.4&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6


#contrib - packages by Centos Users

[contrib]

name=CentOS-6.4 - Contrib - 163.com

baseurl=http://mirrors.163.com/centos/6.4/contrib/x86_64/

#mirrorlist=http://mirrors.163.com/?release=6.4&arch=$basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6" >> /etc/yum.repos.d/CentOS-Base.repo


#####

yum clean all

yum makecache

#yum update


# delete download directory

echo "delete download directory......"

rm -rf /root/tmp4yuan/


 

echo "=========================================================================="

echo "You have successfully replace RedhatEnterprise Yum to CentOS yum and repos"

echo "=========================================================================="

 

sh 该脚本后如若还有问题,那可能是版本问题以下的方法对此问题可能有帮助

1.下载repo文件
1.wget http://mirrors.163.com/.help/CentOS6-Base-163.repo      #你也可以将此地址更换


2.备份并替换系统的repo文件
1.[root@localhost ~]# cd /etc/yum.repos.d/
2.[root@localhost ~]# mv CentOS-Base.repo CentOS-Base.repo.bak
3.[root@localhost ~]# mv CentOS6-Base-163.repo CentOS-Base.repo


3.执行yum源更新
1.[root@localhost ~]# yum clean all
2.[root@localhost ~]# yum makecache
3.[root@localhost ~]# yum update

 

希望对大家有所帮助!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章