Upgrade GCC from Source on Rocky Linux

Jeet Jain
2 min readFeb 22, 2022

Rocky Linux comes with GCC 8.5 installed by default as of now.

$ yum info gcc
Updating Subscription Management repositories.
Installed Packages
Name : gcc
Version : 8.5.0
Release : 4.el8_5
Architecture : x86_64
Size : 59 M
Source : gcc-8.5.0-4.el8_5.src.rpm
Repository : @System
From repo : EOS_Rocky_8_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.

If not, then you can install the above version using the following command:

dnf install gcc -y

Quickly check if you have the default version installed:

$ gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)
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 if you want to install a higher version, you can build & install it from source. Let's start.

Install Development Tools:

sudo dnf group install "Development Tools"

Set GCC version you want to install. We will use 10.2.0 here:

GCC_VERSION=10.2.0

Download & extract GCC binaries:

wget https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar zxf gcc-$GCC_VERSION.tar.gz

Install additional dependencies:

cd gcc-$GCC_VERSION
./contrib/download_prerequisites

Create a build directory

cd - # go back to parent dir
mkdir build && cd build

Build & install

../gcc-10.2.0/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
make install

Once the above steps are completed, you can verify the GCC upgrade:

$ gcc --version
gcc (GCC) 10.2.0 20210514 (Red Hat 10.2.0-2)
Copyright (C) 2020 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.

--

--