APP下载

Linux之RedHat7如何更换yum源

消息来源:baojiabao.com 作者: 发布时间:2026-05-16

报价宝综合消息Linux之RedHat7如何更换yum源

目前,我们常见的系统大概就是Windows、Linux和Mac OS了。Windows系统应该是大部分人最早开始接触的系统,毕竟Windows系统使用起来相当方便,只需要点点鼠标,外加会简单的打字,一般看视讯、听音乐、上网都是没问题的。追求完美体验的使用者可能会更加喜欢Mac OS系统,相比Windows系统而言,Mac OS使用者界面更加的华丽,设计很人性化,使用者体验会好很多。至于Linux,则主要安装在服务器上,一般人基本不太会接触,但是对于运维、开发人员而言,可能是不得不掌握的一种操作系统。

当然,随着资讯科技的发展,全民素质的提高,越来越多的人开始了解Linux并尝试去使用Linux,Linux也逐渐进入了大家的视线。像Ubuntu、Debian、CentOS等Linux系统因为有着类似Windows的桌面和相对人性化的设计而在为人所熟知,大部分初学者基本会安装上述系统来体验一下所谓的Linux系统,如果你对Linux系统也有一定的兴趣,可以去看看《Linux就该这么学》这本书,是一本比较好的Linux入门书籍。

今天,我在这里向大家介绍一下如何为RedHat7更换yum源。选择RedHat的原因很简单:1、RedHat的老板是红帽公司(全球最大的开源技术厂商);2、,RedHat是全世界内使用最广泛的Linux系统。3、RedHat系统具有极强的效能与稳定性,并且在全球范围内拥有完善的技术支援。当然,如果你想要享受红帽公司的技术支援,那是要收费的,如果你不用她的技术支援,那稍稍改变一下,就可以免费使用RedHat系统了,而这个改变就是更换yum源。

如果你新安装了RedHat7,登入系统使用yum update 更新系统时,会得到如下的提示:

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

(换成通俗一点的话,那就是:快来注册,你不注册,就不给你用。)

因为RedHat 预设自带的 yum 源需要注册,才能更新,而我们想不花钱也可以更新,那只能替换掉RedHat的yum源了,下面就给大家介绍一下如果更换RedHat的yum源。

第一步:检查是否安装yum软件包。首先,可以用rpm -qa |grep yum 命令来检视RHEL是否安装了yum,如果安装了,就会显示系统安装的那些yum包:

第二步: 解除安装redhat自带的yum软件包。[[email protected] ~]# rpm -e yum-3.4.3-118.el7.noarch --nodeps

[[email protected] ~]# rpm -e yum-utils-1.1.31-24.el7.noarch --nodeps

[[email protected] ~]# rpm -e yum-rhn-plugin-2.0.1-4.el7.noarch --nodeps

[[email protected] ~]# rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 --nodeps

[[email protected] ~]# rpm -e yum-langpacks-0.4.2-3.el7.noarch --nodeps

[[email protected] ~]# rpm -e PackageKit-yum-0.8.9-11.el7.x86_64 --nodeps

解除安装完成后,再用命令 rpm -qa |grep yum 检视是否已经解除安装完成,如果输入命令后,无资讯显示表示已经解除安装完成:

[[email protected] linuxprobe ~]# rpm -qa |grep yum

[[email protected] linuxprobe ~]#

第三步.下载新的yum软件包。一般可以进入以下网站上面检视软件包的版本是否升级或者找到自己系统所对应的档案包版本更新;

网易163网络源地址:http://mirrors.163.com/

CentOS网络源地址:http://centos.ustc.edu.cn/centos/

找到自己所需要的版本下载:

第四步、安装yum软件包。注意:单个的安装包可能会依赖其它包(例如yum和yum-fastestmirror会相互依赖),所以我们可以把所有这些包放在一起,用一行命令将它们同时安装即可:

[[email protected] ~]# rpm -ivh yum-*

warning: yum-3.4.3-132.el7.centos.0.1.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Preparing... [100%]

Updating / installing...

1:yum-metadata-parser-1.1.4-10.el7 [ 20%]

2:yum-plugin-fastestmirror-1.1.31-3 [ 40%]

3:yum-3.4.3-132.el7.centos.0.1 [ 60%]

4:yum-updateonboot-1.1.31-34.el7 [ 80%]

5:yum-utils-1.1.31-34.el7 [100%]

第五步、新建repo 配置档案。[[email protected] ~]# vim /etc/yum.repos.d/CentOS-Base.repo

#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-$7 - Base - 163.com

#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os

baseurl=http://mirrors.163.com/centos/7/os/$basearch/

gpgcheck=1

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

#released updates

[updates]

name=CentOS-$7 - Updates - 163.com

#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates

baseurl=http://mirrors.163.com/centos/7/updates/$basearch/

gpgcheck=1

gpgkey=http://mirrors.1637

#additional packages that may be useful

[extras]

name=CentOS-$7 - Extras - 163.com

#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras

baseurl=http://mirrors.163.com/centos/7/extras/$basearch/

gpgcheck=1

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$7 - Plus - 163.com

baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/

gpgcheck=1

enabled=0

第六步:执行yum makecache命令生成快取。[[email protected] ~]# yum clean all

[[email protected] ~]# yum makecache

[[email protected] ~]# yum update

经过上述六个步骤,新的yum源已经安装完成了,我们可以用yum install 命令来测试安装是否正常:

[[email protected] ~]# yum -y install lftp

Loaded plugins: fastestmirror, product-id, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile

Resolving Dependencies

--> Running transaction check

---> Package lftp.x86_64 0:4.4.8-7.el7 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size

Installing:

lftp x86_64 4.4.8-7.el7 base 750 k

Transaction Summary

Install 1 Package

………………省略部分安装过程………………

Installed:

lftp.x86_64 0:4.4.8-7.el7

Complete!

到这里,新的yum源已经安装完成了,以后我们就可以用yum命令来愉快的使用RedHat系统了,而不必再担心会出现注册提示无法更新的问题了。

2020-01-11 22:51:00

相关文章