CentOS 8 already comes with GCC 8.

On CentOS 7, you can install GCC 8 from Developer Toolset. First you need to enable the Software Collections repository:

yum install centos-release-scl

Then you can install GCC 8 and its C++ compiler:

yum install devtoolset-8-gcc devtoolset-8-gcc-c++

To switch to a shell which defaults gcc and g++ to this GCC version, use:

scl enable devtoolset-8 -- bash

You need to wrap all commands under the scl call, so that the process environment changes performed by this command affect all subshells. For example, you could use the scl command to invoke a shell script that performs the required actions.

Answer from Florian Weimer on Stack Overflow
🌐
nixCraft
cyberciti.biz › nixcraft › howto › centos › centos / rhel 7: install gcc (c and c++ compiler) and development tools
CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools - nixCraft
April 5, 2024 - Explains how to install GNU C, C++ compiler and other development tools on a CentOS and RHEL (Red Hat Enterprise Linux) version 7.x server/workstation.
Discussions

installation - How to Install gcc 5.3 with yum on CentOS 7.2? - Stack Overflow
I am using CentOS 7.2 When I use yum groupinstall "Development Tools", gcc version is 4.8.5, like this: I would like to install gcc 5.3 How to approach this with yum? More on stackoverflow.com
🌐 stackoverflow.com
CentOS Stream 9 gcc dependency and yum repo install error
This problem should be just about solved now, I'm able to perform multiple runs in containers with no issues. Are you able to successfully hit the repos now? (I recommend running dnf clean all first). More on reddit.com
🌐 r/CentOS
2
6
November 11, 2021
How to OFFLINE install GCC CC and C compiler in LINUX RHEL7.3
A local mirror repo is the best option in my opinion, as u/veive mentioned. You can use tools like reposync to pull down a mirror of active repos to the local machine, and transfer this mirror either to the machine you're wanting to install GCC on or make it available on the same network. Repo URLs do not need to be remote, file URLs are completely valid. This means you can either use a local reposync'd copy made earlier or mounted installation media. If you have installation media for RHEL with the packages you want on it (anything but the minimal and netboot images should work for GCC), you can just point repo configs to their local paths. Some people discussing reposync on CentOS: https://www.centos.org/forums/viewtopic.php?t=61184 Installing from the repos on DVD installation media with RHEL: https://access.redhat.com/solutions/1355683 Using reposync with a RH support subscription (RHN): http://casesup.com/create-a-local-mirror-of-the-latest-update-for-red-hat-enterprise-linux-without-satellite/ A last ditch option if this proves too complex is to just work out the installation RPMs and their dependencies manually, transfer them into your isolated environment and install them directly with yum or rpm - neither tool needs an actual repository to work with, you can just give them a list of pre-downloaded package files to install. This is a fairly manual and annoying process. More on reddit.com
🌐 r/linuxquestions
25
3
September 5, 2018
Please ELI5: How to install packages without root
It's not too hard if you're building an autotools project (one that uses a configure script). For example, I just tried to build the latest version of tmux and saw the following in the output of ./configure --help: By default, make install will install all the files in /usr/local/bin, /usr/local/lib etc. You can specify an installation prefix other than /usr/local using --prefix, for instance --prefix=$HOME On shared computing resources where I don't have root access, I install software into a ~/localRoot directory. I also add ~/localRoot/bin to $PATH and ~/localRoot/lib to $LD_LIBRARY_PATH. Other additional settings may be necessary to fully integrate the localRoot tree. More on reddit.com
🌐 r/linux4noobs
6
11
May 17, 2013
🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
You will need ~1 GB for gcc sources, ~6 GB for the build). Be prepared. This will install gcc in /usr/local/bin/gcc (default prefix is /usr/local). Your distro gcc (/usr/bin/gcc) will not be overwritten, but if later on you need to invoke it, ...
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc compiler on centos 7
How to Install GCC Compiler on CentOS 7 | Linuxize
October 31, 2019 - We’ll explain how to install the distro stable version and the newer version of GCC available from the SCL repository. To add new repositories and install packages on your CentOS system, you must be logged in as root or user with sudo privileges .
🌐
LinuxHostSupport
linuxhostsupport.com › home › how to install gcc on centos 7
How To Install GCC on CentOS 7 | LinuxHostSupport
May 24, 2019 - Run the following command to install GCC on your server ... gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16) 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. As might be seen from the output, the GCC version distributed by CentOS 7 is 4.8.5 which is not the latest version of GCC.
🌐
VietHosting
viethosting.com › home › tutorials › servers › how to install g++ (gcc c++) on centos via command line
How to Install g++ (GCC C++) on CentOS via Command Line
April 8, 2026 - To install the g++ compiler on ... sudo dnf group install "Development Tools" 2. Or install just the C++ compiler: sudo dnf install gcc-c++ Once installed, verify the version by running: g++ --version...
🌐
Medium
bipulkkuri.medium.com › install-latest-gcc-on-centos-linux-release-7-6-a704a11d943d
Install latest GCC from source on Centos Linux release | by Bipul Kuri | Medium
August 18, 2020 - ... And all scripts together. sudo ... ../gcc-8.2.0/configure --enable-languages=c,c++ --disable-multilib make -j$(nproc) sudo make install gcc --version...
Find elsewhere
🌐
Bits and Dragons
bitsanddragons.wordpress.com › 2024 › 04 › 15 › howto-install-and-compile-gcc-on-centos-8-stream
HOWTO: install and compile gcc on CentOS 8 stream. | Bits and Dragons
April 17, 2024 - I'm going to be following this guide. But on CentOS 8 stream. You can skip reading if you don't work on IT, because today I don't find myself specially funny. So this is going to be just technical. We wget gcc-9, and untar it in the chosen location (software) software]# wget https://ftp.gnu.org/gnu/gcc/gcc-9.1.0/gcc-9.1.0.tar.gzsoftware]# tar -xvzf gcc-9.1.0.tar.gz…
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc (development tools) on centos 8
How to Install GCC (Development Tools) on CentOS 8 | Linuxize
March 9, 2020 - The default CentOS repositories contain a package group named “Development Tools” that includes the GNU compiler collection, GNU debugger, and other development libraries and tools required for compiling software. To install the Development Tools packages, run the following command as root or user with sudo privileges : ... The command installs a lot of packages, including gcc, g++ and make.
🌐
Psychz
psychz.net › client › kb › en › how-to-install-the-gcc-compiler-in-centos-7.html
How to install the GCC compiler in CentOS 7? ...
March 17, 2019 - Run the following command to install GCC on your server ... Running transaction test Transaction test succeeded Running transaction Installing : cpp-4.8.5-36.el7.x86_64 1/5 Installing : kernel-headers-3.10.0-957.5.1.el7.x86_64 2/5 Installing : glibc-headers-2.17-260.el7_6.3.x86_64 3/5 Installing : glibc-devel-2.17-260.el7_6.3.x86_64 4/5 Installing : gcc-4.8.5-36.el7.x86_64 5/5 Verifying : glibc-devel-2.17-260.el7_6.3.x86_64 1/5 Verifying : gcc-4.8.5-36.el7.x86_64 2/5 Verifying : kernel-headers-3.10.0-957.5.1.el7.x86_64 3/5 Verifying : cpp-4.8.5-36.el7.x86_64 4/5 Verifying : glibc-headers-2.17-260.el7_6.3.x86_64 5/5 Installed: gcc.x86_64 0:4.8.5-36.el7
Call   800-933-1517
Address   611 Wilshire Blvd #300, 90017, Los Angeles,
🌐
CyberITHub
cyberithub.com › install-gcc-and-c-compiler
Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7 | CyberITHub
January 18, 2020 - Download from Repository and install gcc tool using yum install gcc command.
🌐
JWillikers
jwillikers.com › build-gcc-from-source-on-centos-7
Build GCC From Source on CentOS 7 - JWillikers
October 28, 2020 - Shell commands are provided in both Bash, the native shell on CentOS 7, and fish because it has standards. If you aren’t using the DNF package manager yet, grab that. ... Install the dependencies necessary to build GCC.
🌐
Linux Hint
linuxhint.com › install-gcc-compiler-centos-8
How to Install GCC Compiler on CentOS 8 – Linux Hint
CentOS 8 has a package group named “Development Tools” by default. It includes all the tools required for compiling code, such as GNU, GNU debugger, and development libraries. To install this package group, input the following command: ... This command will install many packages, such as GCC and G++.
🌐
Linux Hint
linuxhint.com › install_gcc_build_tools_centos8
Installing GCC and C/C++ Build Tools on CentOS 8 – Linux Hint
In this article, I am going to show you how to install GCC and all the required C/C++ build tools on CentOS 8 for developing C/C++ programs.
Top answer
1 of 6
233

Update:
Often people want the most recent version of gcc, and devtoolset is being kept up-to-date, so maybe you want devtoolset-N where N={4,5,6,7...}, check yum for the latest available on your system). Updated the cmds below for N=7.

There is a package for gcc-7.2.1 for devtoolset-7 as an example. First you need to enable the Software Collections, then it's available in devtoolset-7:

sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version
2 of 6
78

Update: Installing latest version of gcc 9: (gcc 9.3.0) - released March 12, 2020:

Same method can be applied to gcc 10 (gcc 10.1.0) - released May 7, 2020

Download file: gcc-9.3.0.tar.gz or gcc-10.1.0.tar.gz

Compile and install:

//required libraries: (some may already have been installed)
dnf install libmpc-devel mpfr-devel gmp-devel

//if dnf install libmpc-devel is not working try:
dnf --enablerepo=PowerTools install libmpc-devel

//install zlib
dnf install zlib-devel*

./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

make -j 8 <== this may take around an hour or more to finish
              (depending on your cpu speed)

make install

Tested under CentOS 7.8.2003 for gcc 9.3 and gcc 10.1

Tested under CentOS 8.1.1911 for gcc 10.1 (may take more time to compile)

Results: gcc/g++ 9.3.0/10.1.0

Installing gcc 7.4 (gcc 7.4.0) - released December 6, 2018:

Download file: https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz

Compile and install:

//required libraries:
yum install libmpc-devel mpfr-devel gmp-devel

./configure --with-system-zlib --disable-multilib --enable-languages=c,c++

make -j 8 <== this may take around 50 minutes or less to finish with 8 threads
              (depending on your cpu speed)


make install

Result:

Notes:

1. This Stack Overflow answer will help to see how to verify the downloaded source file.

2. Use the option --prefix to install gcc to another directory other than the default one. The toplevel installation directory defaults to /usr/local. Read about gcc installation options

🌐
LinuxConfig
linuxconfig.org › home › how to install gcc the c compiler on rhel 8 / centos 8
How to install GCC the C compiler on RHEL 8 / CentOS 8
September 24, 2019 - The GCC compiler can be installed in RHEL 8 by simply using the dnf install command.
🌐
VITUX
vitux.com › gcc-compiler-centos
How to Install GCC Compiler Collection on CentOS 8 and Rocky Linux 8 – VITUX
October 21, 2021 - This article will show you how to install the GCC compiler on centos 8. It is important for developers who want to write C/C++ programs for Linux operating systems.
🌐
ComputingForGeeks
computingforgeeks.com › home › install gcc and development tools on rhel 8 / centos 8
Install GCC and Development Tools on RHEL 8 / CentOS 8 [Guide]
August 17, 2023 - Step-by-step guide to gCC and Development Tools on RHEL 8 / CentOS 8. Includes commands, verification, and troubleshooting.
🌐
Medium
medium.com › @zilch0 › gcc-install-gcc-4-9-4-on-centos-7-ce83f5240fe7
[gcc] compile and install gcc 4.9.4 on CentOS 7 - zilch0 - Medium
August 13, 2021 - [gcc] compile and install gcc 4.9.4 on CentOS 7 install dependencies yum update yum install -y glibc-static libstdc++-static yum install gcc gcc-c++ yum install bzip2 2. download gcc 4.9.4 source …