1、刪除redhat原有的yum
rpm -aq|grep yum|xargs rpm -e --nodeps
2、下載yum所需要的安裝包(其中XXX表示版本號)
yum-XXX.el6.centos.noarch.rpm
yum-metadata-parser-XXX.el6.x86_64.rpm
yum-plugin-fastestmirror-XXX.el6.noarch.rpm
python-iniparse-XXX.el6.noarch.rpm
有關這些包的下載地址,我們可以使用centos官方提供的鏡像源(http://mirror.centos.org/),也可以使用網易提供的鏡像源(http://mirrors.163.com/),針對於國內用戶來說,使用網易的鏡像源速度相對快一些。
第一步:首先打開網易鏡像首頁(http://mirrors.163.com/ ),這裏我們選擇centos-6這個版本,對於其他版本的redhat最好選擇與其發行版本號一致的centos源
這裏我們使用centos,打開鏈接
下面有好幾個版本,我們這裏使用6這個版本(如果小版本號中下面沒有東西之後我們可以統一使用6這個來替代)
os下存在着我們所需要的文件
32位請選擇i386,64位請選擇x86_64
Packages下就是所有包的地址,從這裏選擇相應的包進行下載
第二步:下載所需要的rpm包,這裏我們下載如下幾個包(版本號可能會有不一致)
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-30.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
3、安裝yum所需要的軟件包
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
rpm –ivh yum-3.2.29-30.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
注意:最後兩個安裝包要放在一起同時安裝,否則會提示相互依賴,安裝失敗。
4、更改yum源
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
vi CentOS6-Base-163.repo
把文件裏面的$releasever全部替換爲版本號,這裏我們使用版本6(即把$releasever替換爲6)
更改後文件的內容如下
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-6 - Base - 163.com baseurl=http://mirrors.163.com/centos/6/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-6 - Updates - 163.com baseurl=http://mirrors.163.com/centos/6/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-6 - Extras - 163.com baseurl=http://mirrors.163.com/centos/6/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-6 - Plus - 163.com baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-6 - Contrib - 163.com baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
5、清理yum緩存
yum clean all
yum makecache
到此爲止,更改redhat更換yum源的操作就完成了。