CentOS 6、7升級gcc至4.8、4.9、5.2、6.3、7.3等高版本

CentOS 7雖然已經出了很多年了,但依然會有很多人選擇安裝CentOS 6,CentOS 6有些依賴包和軟件都比較老舊,如今天的主角gcc編譯器,CentOS 6的gcc版本爲4.4,CentOS 7爲4.8。gcc 4.8最主要的一個特性就是全面支持C++11,如果不清楚什麼用的也沒關係,簡單說一些C++11標準的程序都需要gcc 4.8以上版本的gcc編譯器編譯,如MySQL 8.0版本(8.0.16以上版本是C++14標準,需gcc 5.3以上版本)。

CentOS 6雖然是gcc 4.4的老舊版本,但是也可以升級gcc來安裝gcc 4.8,我們今天就不採用編譯安裝的方法了,gcc安裝起來非常費時,我們採用CentOS的一個第三方庫SCL(軟件選集),SCL可以在不覆蓋原系統軟件包的情況下安裝新的軟件包與老軟件包共存並且可以使用scl命令切換,不過也有個缺點就是隻支持64位的。

確定當前gcc版本,執行命令:gcc --version

一般如果需要升級gcc至4.8或更高版本,建議直接採用安裝SCL源之後安裝devtoolset-6(devtoolset-6目前gcc版本爲6.3),因爲devtoolset-4及之前的版本都已經結束支持,只能通過其他方法安裝

## 升級到gcc 6.3:

yum -y install centos-release-scl
yum -y install devtoolset-6-gcc devtoolset-6-gcc-c++ devtoolset-6-binutils
scl enable devtoolset-6 bash
需要注意的是scl命令啓用只是臨時的,退出shell或重啓就會恢復原系統gcc版本。
如果要長期使用gcc 6.3的話:

echo “source /opt/rh/devtoolset-6/enable” >>/etc/profile
這樣退出shell重新打開就是新版的gcc了
以下其他版本同理,修改devtoolset版本號即可。

VPS偵探 https://www.vpser.net

升級到gcc 7.3:

yum -y install centos-release-scl
yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令啓用只是臨時的,退出shell或重啓就會恢復原系統gcc版本。
如果要長期使用gcc 7.3的話:

echo “source /opt/rh/devtoolset-7/enable” >>/etc/profile
再說一下已經停止支持的devtoolset4(gcc 5.2)及之前版本的安裝方法

升級到gcc 4.8:

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo
yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
scl enable devtoolset-2 bash
升級到gcc4.9

wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils
scl enable devtoolset-3 bash

升級到gcc 5.2

wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum.repos.d/devtoolset-4.repo
yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils -y
scl enable devtoolset-4 bash

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章