CentOS 升级 gcc 和 g++ 的方法

来源:互联网 发布:关系数据库运算 编辑:程序博客网 时间:2024/06/05 11:54

CentOS 系统自带的 gcc 或者 g++ 的版本是:g++ (GCC) 4.4.6. GCC 版本太旧,导致了很多使用上的不便,如:无法使用g++ -std=c++11 命令来编译 C++11、无法使用Vim的很多插件(YouCompleteMe等)。因此,有必要对它进行升级。

对 GCC 升级无法直接使用:

yum update gcc

以下是升级的详细过程。

1.使用 redhat developer toolset 1.1 的repo,安装GCC

cd /etc/yum.repos.dwget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++

2. 替换系统中原来的GCC

通过通过第一步会把 GCC 安装到以下目录:

/opt/centos/devtoolset-1.1/root/usr/bin/

接下来需要修改系统的配置,使默认的 gcc 和 g++ 命令使用的是新安装的版本。

ln -s /opt/centos/devtoolset-1.1/root/usr/bin/* /usr/local/bin/hash -r

现在查看 g++ 的版本号:

g++ --versiong++ (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5)Copyright (C) 2012 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

已经从4.4.6升级到4.7.2了。