I've confirmed that you can upgrade gcc from the default version 4.8 on centOS 7.

First, we need to install "Software Collections" in order to access some of the community packages including gcc v7

  • sudo yum install -y centos-release-scl

Next, we want to install a developer toolset. Depending on your needs, you may want a different devtoolset. Here I'm targeting 7:

  • sudo yum install -y devtoolset-7

Finally, you'll want to change over to gcc 7 as your default, launch a new shell session with the scl tool:

  • scl enable devtoolset-7 bash
Answer from nulltron on Stack Exchange
🌐
LinuxHostSupport
linuxhostsupport.com › home › how to install gcc on centos 7
How To Install GCC on CentOS 7 | LinuxHostSupport
May 24, 2019 - You need to install the GNU C++ compiler. For Centos “yum install gcc-c++”.
🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
Use the compiler flag ... To enable gcc 9 as default, may have to run the following commands: sudo yum install devtoolset-9-toolchain scl enable devtoolset-9 bash...
Discussions

installation - How to Install gcc 5.3 with yum on CentOS 7.2? - Stack Overflow
2018-06-16T10:43:11.043Z+00:00 ... You can use the centos-sclo-rh-testing repo to install GCC v7 without having to compile it forever, also enable V7 by default and let you switch between different versions if required. sudo yum install -y yum-utils centos-release-scl; sudo yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7... More on stackoverflow.com
🌐 stackoverflow.com
For those who use centos and can't install llama-cpp-python
What you need is to upgrade you gcc version to 11, do as follows: remove old gcc yum remove gcc yum remove gdb install scl-utils sudo yum install scl-utils sudo yum install centos-release-scl find ... More on github.com
🌐 github.com
10
June 6, 2023
linux - GCC-11 installation error in centos 7 (environmental changes)? - Unix & Linux Stack Exchange
I installed the latest version of GCC 11.2V using conda, conda install -c conda-forge gcc" in my linux server (Centos7). After I try to login into my server, after login it shows some weird ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
April 12, 2022
gcc - how to install gcc7 in docker centos7 - Stack Overflow
I am trying to build an docker image based on centos7 FROM centos:centos7 RUN yum -y update RUN yum -y install gcc RUN gcc --version the installed gcc is 4.8: Step 4/4 : RUN gcc --version ---... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - So we will need to pass the option --setopt=group_package_types=mandatory,default,optional to install the optional packages too. Type the following which command or type command/command command to see the gcc binary location.
Top answer
1 of 2
16

I've confirmed that you can upgrade gcc from the default version 4.8 on centOS 7.

First, we need to install "Software Collections" in order to access some of the community packages including gcc v7

  • sudo yum install -y centos-release-scl

Next, we want to install a developer toolset. Depending on your needs, you may want a different devtoolset. Here I'm targeting 7:

  • sudo yum install -y devtoolset-7

Finally, you'll want to change over to gcc 7 as your default, launch a new shell session with the scl tool:

  • scl enable devtoolset-7 bash
2 of 2
1

Enable the software collection in the answer is only effective in the current shell. The scl utility will create a "child-shell" that set the PATH variables properly, so that in the new child-shell, the enabled software collections will be firstly searched. These settings obviously only take effective temporarily in the current shell.

To make it permanently effective, add the command, source /opt/rh/devtoolset-7/enable to the user's profile (~/.bash_profile or ~/.bashrc for RHEL based OS, like CentOS 7). Then, start a new shell and you will have the right tools available.

After execute scl enable devtoolset-7 bash, you will need to execute exit twice to exit the opened shell window, which verifies that the scl command created a new shell instance as a child process. There might be side-effect with creating a child-shell, so do not put this command in the ~/.bashrc profile, otherwise it will repeatedly create child-shell (non-login shell) as each shell will load the profile, resulting in a endless recursive loop. Put it in ~/.bash_profile, it will be loaded for only once (for the login shell), but you will need to exit twice every time.

But for development purpose, scl enable devtoolset-7 bash would be preferred, as you can exit the created child-shell, and then switch between different versions of the same software.


More details about the GCC version in python terminal:

The version info of the built-in Python in CentOS 7:

[root@conda condabuilder]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

The version info of the user installed (via conda) Python on a system even without higher version of GCC installed:

[root@conda condabuilder]# conda activate jupyter
(jupyter) [root@conda condabuilder]# python -VV
Python 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0]

From the results, we can see that the GCC version contained in Python's version info is not related to the system's GCC. The system's default Python (2.7.5) should have been compiled with the GCC version distributed with CentOS 7, so the version info show the same GCC version. But for user installed python, the GCC version info actually depends on what version of GCC is used for building and packging the python binary.

🌐
CyberITHub
cyberithub.com › install-gcc-and-c-compiler
Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7 | CyberITHub
January 18, 2020 - a)You need to have a running CentOS ... commands. In this tutorial, I am using root access. Firstly you need to update your system using yum update command....
🌐
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 .
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

🌐
Medium
bipulkkuri.medium.com › install-latest-gcc-on-centos-linux-release-7-6-a704a11d943d
Install latest GCC on Centos Linux release 7.6
August 18, 2020 - #!/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 ...
Find elsewhere
🌐
GitHub
github.com › imartinez › privateGPT › issues › 644
For those who use centos and can't install llama-cpp-python · Issue #644 · zylon-ai/private-gpt
June 6, 2023 - What you need is to upgrade you gcc version to 11, do as follows: remove old gcc yum remove gcc yum remove gdb · install scl-utils sudo yum install scl-utils sudo yum install centos-release-scl · find devtoolset-11 yum list all --enablere...
Author   zylon-ai
🌐
Ahelpme
ahelpme.com › home › linux › centos 7 › how to install new gcc and development tools under centos 7
How to install new gcc and development tools under CentOS 7 | Any IT here? Help Me!
September 5, 2019 - This article is to install GNU GCC 7 on CentOS 7 and we have a new one to install GNU GCC 8 – How to install GNU GCC 8 on CentOS 7. ... [srv@local ~]# yum -y install centos-release-scl Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.crazyfrogs.org * ...
🌐
JWillikers
jwillikers.com › build-gcc-from-source-on-centos-7
Build GCC From Source on CentOS 7 - JWillikers
October 28, 2020 - CentOS has a pretty old compiler. While the Software Collections repository contains newer versions, it still has a considerable lag-time. So, why not build GCC from source? As it turns out, it’s not actually that hard. This tutorial provides the steps necessary to compile and install a newer version of GCC, version 10.2.0 to be specific, on CentOS 7.
🌐
jdhao's digital space
jdhao.github.io › 2017 › 09 › 04 › install-gcc-newer-version-on-centos
How to Compile and Install Latest Version of GCC on CentOS 7 · jdhao's digital space
April 20, 2019 - curl https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2 -O tar jxvf gcc-5.4.0.tar.bz2 · We need to install 3 dependencies packages. It is recommended to install these packages through yum.
🌐
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 - In the following tutorial, we will perform GCC installation on CentOS 7.
Call   800-933-1517
Address   611 Wilshire Blvd #300, 90017, Los Angeles,
🌐
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 - Install on CentOS 7: INSTALL GCC-C++ (YUM) Copy · sudo yum install gcc-c++ -y · Step 1: Check the version · CHECK VERSION Copy · g++ --version · Step 2: Create source file · CREATE SOURCE FILE Copy · echo '#include · int main() { std::cout ...
🌐
Stack Exchange
unix.stackexchange.com › questions › 585244 › how-do-i-get-gcc-to-run-on-centos-7
How do I get gcc to run on CentOS 7? - Unix & Linux Stack Exchange
May 7, 2020 - Reading back through the logs, yum can't find it. I opened a separate question -- unix.stackexchange.com/questions/585275/… ... You should leave the virtual environment before you are trying to build Python as the venv heavily modifies your environment. Your prompt indicates that you inside a Python virtual environment. When configure fails it usually writes concrete error message into a log file. Check that log file for the root cause. Recent versions of CentOS 7 include dnf, and with that you can install build requirements simply with:
🌐
Centos
lists.centos.org › hyperkitty › list › discuss@lists.centos.org › thread › POTHJYRWJSSESJ3TWDHO76JIMAXZBYCS
Package of GCC 12 on CentOS 7 - Discuss - lists.centos.org
Is there an rpm of GCC 12 (or at least higher than 9) available to download and install, or is it a case of downloading and build from the source yourself?