轉載地址: https://www.cnblogs.com/syqlp/p/6555524.html (親測有效)
背景:
新安裝了redhat7.安裝後,登錄系統,使用yum update 更新系統。提示:
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
無法更新。
redhat 默認自帶的 yum 源需要註冊,才能更新。我們想不花錢也可以更新,需要替換掉redhat的yum源。
1.檢查是否安裝yum包
查看RHEL是否安裝了yum,若是安裝了,那麼又有哪些yum包:
[root@syq yum.repos.d]# rpm -qa |grep yum
yum-3.4.3-118.el7.noarch
yum-utils-1.1.31-24.el7.noarch
yum-rhn-plugin-2.0.1-4.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-langpacks-0.4.2-3.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
2 刪除redhat自帶的yum包
卸載上面顯示的所有yum包:
[root@localhost ~]# rpm -qa|grep yum|xargs rpm -e --nodeps(不檢查依賴,直接刪除rpm包)
再用
[root@localhost ~]# rpm -qa |grep yum
[root@localhost ~]#
查看,無信息顯示錶示已經卸載完成。
此外,以免出現兼容問題,最好再刪除python-urlgrabber包,重新安裝較新的包:
[root@localhost ~]#rpm -qa|grep python-urlgrabber|xargs rpm -e --nodeps
3.下載新的yum包,使用Centos7的yum包
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-150.el7.centos.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-40.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
注:這裏包的版本可能與實際倉庫裏面有衝突,請以倉庫裏面最新版本爲準!
4.安裝yum軟件包
注意:單個的安裝包可能會依賴其它包(例如yum和yum-fastestmirror會相互依賴),所以我們可以把所有這些包放在一起,用一行命令將它們同時安裝即可:
rpm -ivh python-urlgrabber-3.10-8.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-3.4.3-150.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-40.el7.noarch.rpm
5.更換yum源。使用阿里雲的源
第一步:下載新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
注:更改CentOS-Media.repo使其爲不生效:
enabled=0
第二步:修改CentOS-Base.repo文件中的$releasever全部替換爲版本號7 第三步:運行yum makecache生成緩存
yum clean all
yum makecache
yum update