CentOS 7 安装 gcc 9.2.0

yum 源里最新的 gcc 版本是 4.8.5,但很多时候安装软件依赖于更高版本的 gcc,这时候只能通过手动源码安装最新版。

使用源码编译安装gcc耗时非常大,请要有耐心等待,耐心等待,耐心等待,重要的事情说三遍。

如果你觉得步麻烦可以使用 gcc一键安装 帮你完成!

1、下载并解压源码

wget https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
tar -zxf gcc-9.2.0.tar.gz
cd gcc-9.2.0

备用下载地址:https://down.24kplus.com/linux/gcc-9.2.0.tar.gz

2、编译安装

下载必要软件包

./contrib/download_prerequisites

如果提示 tar (child): lbzip2: Cannot exec: No such file or directory 错误:

yum -y install bzip2

编译安装gcc

./configure --prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--enable-bootstrap \
--enable-shared \
--enable-threads=posix \
--enable-checking=release \
--with-system-zlib \
--enable-__cxa_atexit \
--disable-libunwind-exceptions \
--enable-gnu-unique-object \
--enable-linker-build-id \
--with-linker-hash-style=gnu \
--enable-languages=c,c++ \
--enable-plugin \
--enable-initfini-array \
--disable-libgcj \
--enable-gnu-indirect-function \
--with-tune=generic \
--with-arch_32=x86-64 \
--build=x86_64-redhat-linux \
--disable-multilib
make
make install

如果出现 configure: error: GNAT is required to build ada 错误

yum -y install gcc-gnat -y

如果出现 fatal error: zlib.h: No such file or directory 错误

yum install zlib-devel -y

如果出现 configure: error: C++ preprocessor "/lib/cpp" fails sanity check 错误

yum install gcc-c++ -y

如果出现 makeinfo: command not found 错误

yum install texinfo -y

为了避免日后编译软件发生 checking for C compiler … not found 错误,执行:

ln -s /usr/bin/gcc /usr/bin/cc

4、检查是否正确安装

gcc -v