出处:http://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos
执行以下命令
cd /etc/yum.repos.d
wget 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++
成功后安装于目录
/opt/centos/devtoolset-1.1/root/usr/bin/
版本为 4.7.2
设置环境变量取代默认gcc:
export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc
export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
有些源代码依赖于较高的gcc版本,这是解决办法。
gcc 4.8.1和4.8.2在此:https://people.centos.org/tru/devtools-2/
参考上述办法安装。