RedHat yum安装gcc-c++失败原因及解决思路
刚步入职场时,在为Linux RedHat系统搭建开发环境的过程中,遭遇了一个棘手的问题。
[root@localhost ~]# yum -y install gcc
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Install Process
No package gcc available.
Nothing to do
对于习惯了CentOS操作的用户而言,在RedHat上无法直接使用yum命令进行软件包管理,这种体验无疑令人感到困扰。
以下是具体的排查与解决步骤:
第一步,获取CentOS系统的镜像源配置文件。
[root@localhost~]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2026-10-09 14:33:10-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
Resolving mirrors.163.com... 123.58.173.186,123.58.173.185
Connecting to mirrors.163.com|123.58.173.186|:80...connected.
HTTP request sent, awaiting response... 200 OK
Length: 2341 (2.3K) [application/octet-stream]
Saving to: `CentOS6-Base-163.repo'
100%2,341 --.-K/s in 0s
2026-10-09 14:33:22 (108 MB/s) -`CentOS6-Base-163.repo' saved [2341/2341]
第二步,对yum的repo配置文件进行修改和适配。
[root@localhost~]# mv CentOS6-Base-163.repo /etc/yum.repos.d/
*** 把$releasever替换成6
[root@localhost yum.repos.d]# sed -i 's#$releasever#6#g' ./CentOS6-Base-163.repo
第三步,清除系统中现有的所有yum缓存数据。
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Cleaning up Everything
第四步,重新生成并获取最新的yum软件包列表。
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
addons | 1.9 kB 00:00
addons/filelists_db | 570 B 00:00
........
........
base 3667/3667
base 3667/3667
base 3667/3667
Metadata Cache Created
第五步,在列表中搜索目标软件包。
[root@localhost ~]# yum search gcc |grep --color '^gcc'
gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
gcc-c++.x86_64 : C++ support for GCC
gcc-gfortran.x86_64 : Fortran 95 support
gcc-gnat.x86_64 : Ada 95 support for GCC
gcc-java.x86_64 : Java support for GCC
gcc-objc++.x86_64 : Objective-C++ support for GCC
gcc-objc.x86_64 : Objective-C support for GCC
gcc44.x86_64 : GNU Compiler Collection version 4.4
gcc44-c++.x86_64 : C++ support for GCC version 4.4
gcc44-gfortran.x86_64 : Fortran support for GCC 4.4
第六步,执行gcc的安装命令。
[root@localhost yum.repos.d]# yum -y install gcc
至此,gcc已成功安装,其他编译环境的依赖也可以通过yum正常获取了。
总结
以上分享了在RedHat环境下解决yum无法安装gcc-c++的具体流程,希望能对大家有所帮助。如有任何疑问,欢迎留言交流,小编会及时回复。感谢大家对本站的支持!