
1.检查是否安装yum软件包
- 首先,查看RHEL是否安装了yum,如果安装了,就会显示系统安装的那些yum包:
rpm -qa|grep yum
-
结果如下:
image.png
2.卸载这些软件包
- 一个命令删除
rpm -qa|grep yum|xargs rpm -e --nodeps
- 或者一个一个地删除
rpm -e <软件包> --nodeps
- 卸载完成后,再用命令 rpm -qa|grep yum 查看是否已经卸载完成,如果输入命令后,无信息显示表示已经卸载完成
3.进入centos镜像网站找到自己对应系统需要的yum包
(1)查看系统的命令
cat /etc/redhat-release
如图:

(2)查看系统的位数:
file /bin/ls
如图:

(3)CentOS网络源找到与自己系统对应的yum依赖包
-
CentOS网络源地址:http://vault.centos.org
-
在http://vault.centos.org/7.6.1810/os/x86_64/Packages/找到依赖包
yum-1.1.10-1.el7.centos.x86_64.rpm
yum-plugin-1.1.10-1.el7.centos.x86_64.rpm
-
使用命令:
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/PackageKit-yum-1.1.10-1.el7.centos.x86_64.rpm
wget http://vault.centos.org/7.6.1810/os/x86_64/Packages/PackageKit-yum-plugin-1.1.10-1.el7.centos.x86_64.rpm
4.安装yum依赖包
- 注意:单个的安装包可能会依赖其它包所以我们可以把所有这些包放在一起,用一行命令将它们同时安装即可
- 使用命令:
rpm -ivh yum-*
5.更新centos系统的repo文件
- 使用命令:
vi /etc/yum.repos.d/CentOS-Base.repo
在yum.repos.d/路径下新建配置文件
- 加入内容可以参考http://mirrors.ustc.edu.cn/help/centos.html里对应版本的内容,但我尝试了发现yum makecache 不了,在网上搜索到和其内容大体一致,删除了一些不存在的网址的子路径
内容如下:
# 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=$releasever&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=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#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
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
6.运行yum makecache命令生成缓存。
- 命令如下:
yum clean all
yum makecache
yum update
经过上述六个步骤,新的yum源已经安装完成了
7.用yum install gcc 成功了安装gcc
注意替换了yum源会影响内核
网友评论