Upgrade GCC from source on Centos 8 Linux release

Bipul Kuri
3 min readAug 18, 2020

--

Lets upgrade gcc in centos 8 from source,We upgraded to gcc 9.2.0

If gcc is not installed,install it

dnf install gcc -y

Basic Centos8 comes with gcc 8.3.1

$yum info gcc
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:35 ago on Tue Aug 18 02:10:41 2020.
Installed Packages
Name : gcc
Version : 8.3.1
Release : 5.el8.0.2
Architecture : x86_64
Size : 59 M
Source : gcc-8.3.1-5.el8.0.2.src.rpm
Repository : @System
From repo : AppStream
Summary : Various compilers (C, C++, Objective-C, ...)
URL : http://gcc.gnu.org
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : The gcc package contains the GNU Compiler Collection version 8.
: You'll need this package in order to compile C code.

or

$dnf info  gcc
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:05:07 ago on Tue Aug 18 02:10:41 2020.
Available Packages
Name : gcc
Version : 8.3.1
Release : 5.el8.0.2
Architecture : x86_64
Size : 23 M
Source : gcc-8.3.1-5.el8.0.2.src.rpm
Repository : AppStream
Summary : Various compilers (C, C++, Objective-C, ...)
URL : http://gcc.gnu.org
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : The gcc package contains the GNU Compiler Collection version 8.
: You'll need this package in order to compile C code.

Make sure a gcc version is installed on the box,so for our case we have this installed

$gcc --version
gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)
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.

Lets first install development tools

sudo dnf group install "Development Tools"

Install libmpc as it was not present in my Centos 8

dnf --enablerepo=PowerTools install libmpc-develor$wget https://rpmfind.net/linux/centos/8.1.1911/PowerTools/x86_64/os/Packages/libmpc-devel-1.0.2-9.el8.x86_64.rpm
$rpm -ivh libmpc-devel-1.0.2-9.el8.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:libmpc-devel-1.0.2-9.el8 ################################# [100%]

Build make and install

GCC_VERSION=9.2.0
wget http://gnu.mirror.constant.com/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar zxf gcc-$GCC_VERSION.tar.gz
rm -rf gcc-build
mkdir gcc-build
cd gcc-build
../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
make install

after gcc upgrade

gcc-build]# gcc --version
gcc (GCC) 9.2.0
Copyright (C) 2019 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.

my final script

#!/bin/sh
GCC_VERSION=9.2.0
dnf update -y
dnf group install "Development Tools"
gcc --version
dnf --enablerepo=PowerTools install libmpc-devel
wget http://gnu.mirror.constant.com/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar zxf gcc-$GCC_VERSION.tar.gz
rm -rf gcc-build
mkdir gcc-build
cd gcc-build
../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
make install
gcc --version
cd ..

--

--

No responses yet