天天看點

CentOS完美更新gcc方案

在某些應用場景中,需要特定的gcc版本支援,但是輕易不要去編譯gcc,我這裡推薦使用紅帽提供的開發工具包來管理gcc版本,這樣做的好處是随時切換版本,并且可以并存多個版本,不破壞原有gcc環境。

紅帽官方Developer Toolset文檔位址:

https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/8/ https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/8/ devtoolset對應gcc的版本

devtoolset-3對應gcc4.x.x版本
devtoolset-4對應gcc5.x.x版本
devtoolset-6對應gcc6.x.x版本
devtoolset-7對應gcc7.x.x版本      

安裝devtoolset包

yum install centos-release-scl
yum install devtoolset-4      

激活gcc版本,使其生效

scl enable devtoolset-4 bash      

source /opt/rh/devtoolset-4/enable      

此時通過gcc --version指令可以看到,gcc版本已經變成5.3.1,值得注意的是這僅僅在目前bash生效,如果需要永久生效,可以請自行添加環境變量。

繼續閱讀