tar -zxvf gcc-8.4.0.tar.gz
- 下載依賴
yum -y install bzip2 zlib zlib-devel
yum -y install gcc gcc-c++ gdb
將文件 ./contrib/download_prerequisites 中的地址:
ftp://gcc.gnu.org/pub/gcc/infrastructure/
替換為:
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/infrastructure/
然后執行下載依賴:
cd gcc-8.4.0
chmod +x /opt/gcc-8.4.0/contrib/download_prerequisites
./contrib/download_prerequisites
- 新建編譯目錄
mkdir build
cd build
- 配置參數
/opt/gcc-8.4.0/configure --prefix=/usr/local/gcc-8.4.0 --enable-threads=posix --disable-checking --disable-multilib --enable--long-long --with-system-zlib --enable-languages=c,c++
- 編譯安裝
make -j8
make install
- 配置默認為 gcc-8.4.0
ln -snf /usr/local/gcc-8.4.0/bin/gcc /usr/bin/gcc
ln -snf /usr/local/gcc-8.4.0/bin/g++ /usr/bin/g++
- 查看版本
gcc --version
g++ --version