设为首页 加入收藏

TOP

centOS 7安装最新版gcc、g++(一)
2023-07-23 13:33:41 】 浏览:49
Tags:centOS 安装最 gcc

centOS7安装gcc g++

个人博客:www.cppbugboy.cn

在使用yum时遇到这个错误
Another app is currently holding the yum lock; waiting for it to exit…

运行命令

rm -f /var/run/yum.pid	//	 有其他进程正在占用yum,先强制关掉yum

一、第一种方式

1、先卸载以前的旧版本

因为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: /usr/bin/gcc: No such file or directory
[root@123 /]# g++ -v
-bash: /usr/bin/g++: No such file or directory

这样即为卸载成功

2、安装最新版本的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@123 /]# 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-20210728/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 20210728 (Red Hat 11.2.1-1) (GCC)
[root@123 /]# 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-20210728/obj-x86_64-redhat-linux/isl-install --enable-gnu-indirect-function --with-tune=generic
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇CentOS7内置Realtek网卡驱动r8169.. 下一篇计算机硬件的读写速度差异

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目