centOS7安装最新版 gcc g++

10 篇文章 1 订阅
本文详细指导了如何在CentOS系统中卸载旧版本的gcc和g++,解决依赖问题,然后安装最新版本的11版,并配置环境变量,确保跨客户端使用。
摘要由CSDN通过智能技术生成

一、先卸载以前的旧版本

因为centOS默认自带4点几版本的gcc 、g++编译器,是比较老的版本的,所以先把老版本卸载掉。

1、 先获取root权限
2、 查看当前的安装版本号

rpm -q gcc

3、卸载掉旧版本

rpm -e [第二步查到的版本号]

4、第三步可能会遇到如下错误,卸载失败

error: Failed dependencies:
gcc = 4.4.7-23.el6 is needed by (installed) gcc-c++-4.4.7-23.el6.x86_64
gcc = 4.4.4 is needed by (installed) libtool-2.2.6-15.5.el6.x86_64

提示要卸载的版本有两个依赖,要先卸载掉这两个依赖(注意:下面要卸载的版本号要和上面提示的两个依赖的版本号一致)

rpm -e gcc-c++-4.4.7-23.el6.x86_64
rpm -e libtool-2.2.6-15.5.el6.x86_64

将这两个依赖卸载完成之后再次执行第3步就可卸载成功

5、验证卸载

[root@123 /]# gcc -v
bash: gcc: command not found
[root@123 /]# g++ -v
bash: g++: command not found

这样即为卸载成功

二、安装最新版本的gcc 、g++

在安装之前,可以先去查询一下目前gcc 、g++的版本以及区别,本文用了第11版

1、在系统中安装存储库

yum install centos-release-scl

2、安装gcc和g++包(注意版本号:11版)

yum install -y devtoolset-11-gcc devtoolset-11-gcc-c++

3、配置安装好的包(注意版本号:11版)

scl enable devtoolset-11 bash

4、验证安装

[root@wyx ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-11/root/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-11/root/usr --mandir=/opt/rh/devtoolset-11/root/usr/share/man --infodir=/opt/rh/devtoolset-11/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-linux/isl-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) 
[root@wyx ~]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-11/root/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-11/root/usr --mandir=/opt/rh/devtoolset-11/root/usr/share/man --infodir=/opt/rh/devtoolset-11/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-linux/isl-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) 

5、配置环境变量
因为不配置环境变量的话,每打开一个客户端,就需要执行一次上面的第三步配置安装包。

先查看gcc和g++安装位置:

[root@wyx /]# which gcc
/opt/rh/devtoolset-11/root/usr/bin/gcc
[root@wyx /]# which g++
/opt/rh/devtoolset-11/root/usr/bin/g++

编辑文件

vim /etc/profile

在文件后面添加下面两行内容:

PATH=$PATH::/opt/rh/devtoolset-11/root/usr/bin
export PATH

重新加载文件

source /etc/profile
  • 11
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在CentOS中安装最新版gcc,你可以按照以下步骤进行操作: 1. 首先,你可以使用以下命令检查CentOS自带的gcc版本: ```shell gcc -v ``` 如果你的版本较旧,你可以选择升级到最新版。否则,你可以跳过此步骤。 2. 使用以下命令使用yum安装旧版本的gccg++: ```shell sudo yum install -y gcc sudo yum install -y gcc-c++ ``` 3. 接下来,你需要从官方网站下载你想要安装最新版gcc。你可以访问gcc的官方网站(https://gcc.gnu.org/)来获取最新版本的gcc。 4. 下载完最新版gcc后,将其解压并进入解压后的目录。你可以使用以下命令: ```shell tar -zxf gcc-<version>.tar.gz cd gcc-<version> ``` 注意将`<version>`替换为你下载的gcc版本号。 5. 在进入解压后的gcc目录后,你可以根据需要执行配置和安装步骤。具体步骤可能因版本而异,请查阅gcc的官方文档或README文件来获取详细的安装步骤。 以上是在CentOS中安装最新版gcc的一般步骤。请根据实际情况和需要进行相应的调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [centOS7安装最新版 gcc g++](https://blog.csdn.net/qq_45316173/article/details/122018354)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [centos安装最新版gccgcc-12.1.0)记录](https://blog.csdn.net/weixin_42637826/article/details/128860023)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值