Install latest GCC from source on Centos Linux release

Bipul Kuri
3 min readJan 5, 2019

When you have to upgrade gcc to build some application.

*Update Tested for gcc 9.2.0 version

Following are the steps documented for upgrading gcc on centos 7

Let’s update the box

sudo yum -y update

Now that the update is done lets install the dependencies needed for the build.This is important you don’t want to wait to find one of the build dependencies were missing after 2hr’s of build

sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make

Looks like the gcc is really old version

gcc --version                       
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) 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.

Lets start the upgrade part

Next we will download the tar file from gcc mirror gcc-8.2.0.tar.gz from official mirror page http://gcc.gnu.org/mirrors.html and http://mirrors-usa.go-parts.com/gcc/releases/gcc-8.2.0/ . Choose different location based on your geo location.

In future the release numbers will differ but overall steps should be same

wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz

Untar the file

tar zxf gcc-8.2.0.tar.gz

Create a separate build folder for our work, we should not mess up with the source code

mkdir gcc-8.2.0-build
cd gcc-8.2.0-build

Give configuration options more details can be found here https://gcc.gnu.org/install/configure.html.

../gcc-8.2.0/configure --enable-languages=c,c++ --disable-multilib

Be sure that you have enough free diskspace in /tmp. Free /tmp folder before make .Start the make,this may take a while.Adjust -j number to available cpu cores. Be careful this step takes time ,run it in background if possible.

make -j$(nproc)

Finally install ,default install will be at /usr/local

sudo make install

Finish with verification.

gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 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.

Now put the gcc in path

export PATH=/usr/local/bin:$PATHexport LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

And all scripts together.

sudo yum -y update
sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make
gcc --version
wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz
tar zxf gcc-8.2.0.tar.gz
mkdir gcc-8.2.0-build
cd gcc-8.2.0-build
../gcc-8.2.0/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
sudo make install
gcc --version

tested in a shell script with version 9.2.0

#!/bin/shGCC_VERSION=9.2.0
sudo yum -y update
sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make
gcc --version
wget http://gnu.mirror.constant.com/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar zxf gcc-$GCC_VERSION.tar.gz
mkdir gcc-build
cd gcc-build
../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
sudo make install
gcc --version
cd ..
rm -rf gcc-build

or follow this article from Red Hat itself.

--

--