不像4.9.2, 升級4.8.5的gcc版本只需1GB的内存即可, 另外說一句, 4.9.2如果内存不夠會中途報錯, 通過調整swap大小來解決問題。
yum腳本自動安裝
目前這個yum倉庫可以安裝三種高版本的gcc。
4.8安裝
curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo yum install gcc gcc-g++ -y g++ --version
4.9安裝
yum install centos-release-scl -y yum install devtoolset-3-toolchain -y scl enable devtoolset-3 bash gcc --version gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. g++ --version g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. gfortran --version GNU Fortran (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING
5.2安裝
yum install centos-release-scl -y yum install devtoolset-4-toolchain -y scl enable devtoolset-4 bash gcc --version gcc (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. g++ --version g++ (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
手動安裝
獲取GCC 4.8.5包(加拿大鏡像):
wget http://gcc.skazkaforyou.com/releases/gcc-4.8.5/gcc-4.8.5.tar.gz
如果鏡像掛了, 還有這兩個鏡像
wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.1/gcc-4.8.1.tar.bz2
解壓縮:
tar -xf gcc-4.8.5.tar.gz
進入到目錄gcc-4.8.5,
cd gcc-4.8.5
運行:
./contrib/download_prerequisites
這個腳本會幫我們下載、配置、安裝依賴庫。
建立輸出目錄並到目錄裡:
mkdir gcc-build-4.8.5 cd gcc-build-4.8.5 ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
–enable-languages表示你要讓你的gcc支持那些語言,-disable-multilib不生成編譯爲其他平台可執行代碼的交叉編譯器。-disable-checking生成的編譯器在編譯過程中不做額外檢查,也可以使用-enable-checking=xxx來增加一些檢查;
編譯和安裝, 等待時間較長:
make && make install
驗证:
gcc -v
或者g++ -v,如果顯示的gcc版本仍是以前的版本,就需要重啓系統;或者可以查看gcc的安裝位置:which gcc;然後在查看版本 /usr/local/bin/gcc -v,通常gcc都安裝在該處位置。
問題解決
make報錯
configure: error: C++ compiler missing or inoperational
需要安裝編譯器, yum安裝命令爲:
yum install gcc-c++
再make解決