Install gcc 7.3.0 on CentOS7.5:
by default gcc4.8.5 installed on CentOS7.5:
1). install package related:
yum -y groupinstall "Development Tools"
yum -y install libmpc-devel mpfr-devel gmp-devel zlib-devel* glibc-static libstdc++-static
2). download gcc from gnu.org, and compile it:
curl -C - ftp://ftp.gnu.org/pub/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz -O
tar xvf gcc-7.3.0.tar.gz
cd gcc-7.3.0
Also can specify other languages wanna gcc support, e.g.: go
by default, gcc will installed /usr/local/bin/:
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++
make # or make -j3 # or make -j16 # if 16 CPU cores.
make install
3). export CC, CXX before CMake, append those two lines at the end of /etc/profile:
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
[root@localhost bin]# tail /etc/profile
unset -f pathmunge
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/mysql/mysql/lib/:/usr/local/include/boost/lib/
export LD_LIBRARY_PATH
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
4). check gcc, g++ version:
gcc --version
g++ --version
[root@localhost bin]# which g++
/usr/local/bin/g++
[root@localhost bin]# g++ --version
g++ (GCC) 7.3.0
Copyright (C) 2017 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.
[root@localhost bin]# which gcc
/usr/local/bin/gcc
[root@localhost bin]# gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 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.
[root@localhost bin]#
tip: Or a alternatives that DIRECTLY install centos-release-scl and devtoolset-7 as below:
- Install centos-release-scl and devtoolset-7:
yum -y install centos-release-scl devtoolset-7
- Add 'scl enable devtoolset-7 bash' to /etc/profile like below:
echo "scl enable devtoolset-7 bash" >> /etc/profile
[root@localhost ~]# tail /etc/profile
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/mysql/mysql/lib/:/usr/local/include/boost/lib/
export LD_LIBRARY_PATH
#export CC=/usr/bin/gcc
#export CXX=/usr/bin/g++
#export CC=/usr/local/bin/gcc
#export CXX=/usr/local/bin/g++
scl enable devtoolset-7 bash
[root@localhost ~]#
Now the gcc version is 7.3.1-5:
[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)
[root@localhost ~]#