CentOS7 升级gcc版本

问题:

安装需要编译的node包的时候,会报错:

npm ERR! g++: 错误:unrecognized command line option ‘-std=gnu++14’
npm ERR! make: *** [Release/obj.target/syslog/src/main.o] 错误 1

因为CentOS目前自带的gcc是4.8.5的,需要升级gcc来解决这个问题。当然也有建议使用低版本的node环境重新安装node包的。

下面总结一下,好用且亲测好使的升级gcc版本的方法

yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
scl enable devtoolset-8 bash  #启动gcc8

  你要哪个版本的就把第2条命令中的数字8改成你要的主版本号就可以了。这样升级到的是最新的版本。例如8升级到的是8.2.0而不是8.1。

除了了gcc 8,scl中还有如下gcc版本:

  • devtoolset-3: gcc 4.9
  • devtoolset-4: gcc 5
  • devtoolset-6: gcc 6
  • devtoolset-7: gcc 7
  • devtoolset-8: gcc 8

  通过scl命令启动gcc,这个只是暂时的,当你的shell关闭后或者重启就会恢复原来的版本,要想一直使用升级后的版本可以使用如下命令:

echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
echo "source /opt/rh/devtoolset-8/enable" >> /etc/bashrc
source /etc/bashrc 

在看到过其他方案的,就是替换软连接的。

mv /usr/bin/gcc /usr/bin/gcc-4.8.5

ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc

mv /usr/bin/g++ /usr/bin/g++-4.8.5

ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++

gcc --version

g++ --version

你可能感兴趣的:(linux,Node.js,linux,centos,运维)