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
🌐
The Linux Cluster
thelinuxcluster.com › 2022 › 07 › 01 › compiling-gcc-10-4-0-on-centos-7
Compiling GCC-10.4.0 on CentOS-7 – The Linux Cluster
July 1, 2022 - Step 1: Download the TarBall version of GCC version. If you want to take look at all the available versions, you can take a look at http://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/ For this blog entry, we will install GCC-10.4.0. ...
Discussions

c++ - How to enable later versions of GCC in eclipse CDT in CentOS 7 - Stack Overflow
My CentOS 7 machine has a default GCC version of 4.8.5. I want to use a higher version of GCC. So, I executed the following steps in a terminal: sudo yum install centos-release-scl sudo yum install devtoolset-10-gcc* scl enable devtoolset-10 bash More on stackoverflow.com
🌐 stackoverflow.com
LLVM 14 breaks using lld with devtoolset-10 gcc on CentOS 7
Commit 815a120 removed support for --no-add-needed. However, this option is added by devtoolset-10 gcc on CentOS7: [sgiesecke@SDP_DevVM-sgiesecke gcc]$ scl enable devtoolset-10 -- gcc test.cc -fuse-ld=lld -B /bin -v Using ... More on github.com
🌐 github.com
5
April 5, 2022
How to install GCC/G++ 8 on CentOS - Stack Overflow
You can find more details for working ... so that gcc/g++ 8 will always be in your path. 2019-03-26T22:22:43.15Z+00:00 ... # yum install centos-release-scl No match for argument: centos-release-scl I'm using CentOS 8. Where can I get the packages installed here? 2020-01-16T12:22:08.223Z+00:00 ... It helps on CentOS 7. Just replace the 8 with 10 to install ... More on stackoverflow.com
🌐 stackoverflow.com
Beginner with Centos. What is best way to upgrade GCC?
Centos 7 The latest stable release is 8 and I think Stream is on 9, is there a reason you're using a decade-old release? You could try installing distrobox (or toolbox) and set up a Fedora container for your compiler. This way it won't conflict with anything and you avoid dependency hell. You'll still need to upgrade to 8 at least though, since 7 only ships an old version of podman that probably doesn't even support rootless containers. More on reddit.com
🌐 r/linuxquestions
26
1
October 28, 2022
🌐
JWillikers
jwillikers.com › build-gcc-from-source-on-centos-7
Build GCC From Source on CentOS 7 - JWillikers
October 28, 2020 - cmake \ -DCMAKE_C_COMPILER=$HO... ancient CentOS system.[1] Now, what are you waiting for? Start using std::span! 1. That’s right, CentOS 7 uses the pre-C++11 ABI....
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › compute module
help : centos7.9 can't install gcc 10 - Raspberry Pi Forums
_CFLAGS_FOR_TARGET='' DEFS='-DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DLT_OBJDIR=\".libs/\"' DLLTOOL='armv7l-dlltool' DLLTOOL_FOR_BUILD='dlltool' DLLTOOL_FOR_TARGET='dlltool' ECHO_C='' ECHO_N='-n' ECHO_T='' EXEEXT='' EXPECT='expect' FLAGS_FOR_TARGET='' FLEX='flex' GCC_FOR_TARGET='cc' GCC_SHLIB_SUBDIR='' GDB_TK='' GDC_FOR_BUILD='gdc' GDC_FOR_TARGET='gdc' GFORTRAN_FOR_BUILD='gfortran' GFORTRAN_FOR_TARGET='gfortran' GNATBIND='no' GNATMAKE='no' GOC_FOR_BUILD='gccgo' GOC_FOR_TARGET='gccgo' INSTALL_DATA='${INS
🌐
LinuxHostSupport
linuxhostsupport.com › home › how to install gcc on centos 7
How To Install GCC on CentOS 7 | LinuxHostSupport
May 24, 2019 - In this tutorial, we will take ... is a standard compiler on many Unix operating systems such as Linux. Installing GCC on CentOS 7, is really an easy task and it shouldn’t take more than 10 minutes....
🌐
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 - Note: You need to log in to your CentOS 7 VPS via SSH as user root ... GCC can be easily installed from the official CentOS repositories. Run the following command to install GCC on your server ...
Call   800-933-1517
Address   611 Wilshire Blvd #300, 90017, Los Angeles,
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.

Find elsewhere
🌐
CyberITHub
cyberithub.com › install-gcc-and-c-compiler
Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7 | CyberITHub
January 18, 2020 - In this article I will take you through the steps to install GCC on CentOS 7. As per GCC Document ,The GNU Compiler Collection includes front ends for C, C++,
🌐
Wii Blog
wfeii.com › 2021 › 01 › 25 › centos7-gcc10.html
CentOS 7 编译安装 GCC 10.2.0
January 25, 2021 - 环境准备 系统版本 $ cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) 安装编译环境 $ sudo yum install gcc gcc-c++ glibc-static wget xz bzip2 $ gcc -v 使用内建 specs。 COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper 目标:x86_64-redhat-linux 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind
🌐
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 - 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
🌐
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.
🌐
Red Hat
developers.redhat.com › blog › 2020 › 09 › 24 › new-c-features-in-gcc-10
New C++ features in GCC 10 | Red Hat Developer
February 5, 2024 - Fedora 32 already ships GCC 10 as the system compiler, but it's also possible to try GCC 10 on other platforms (see godbolt.org, for example). Red Hat Enterprise Linux (RHEL) users will get GCC 10 in the Red Hat Developer Toolset (RHEL 7), or the Red Hat GCC Toolset (RHEL 8).
🌐
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.
🌐
GitHub
github.com › llvm › llvm-project › issues › 54756
LLVM 14 breaks using lld with devtoolset-10 gcc on CentOS 7 · Issue #54756 · llvm/llvm-project
April 5, 2022 - Commit 815a120 removed support for --no-add-needed. However, this option is added by devtoolset-10 gcc on CentOS7: [sgiesecke@SDP_DevVM-sgiesecke gcc]$ scl enable devtoolset-10 -- gcc test.cc -fuse-ld=lld -B /bin -v Using ...
Author   llvm
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 10 › html › user_guide › chap-gcc
Chapter 2. GNU Compiler Collection (GCC) | User Guide | Red Hat Developer Toolset | 10 | Red Hat Documentation
All compilers from Red Hat Enterprise ... 6, and 7 and from Red Hat Developer Toolset versions 1 to 10 in any -std mode are compatible with any other of those compilers in C++98 mode. A compiler in C++11, C++14, or C++17 mode is only guaranteed to be compatible with another compiler in those same modes if they are from the same release series. ... The GCC compiler in ...
🌐
idroot
idroot.us › home › how to install gcc on centos 7
How To Install GCC on CentOS 7 - idroot
July 23, 2024 - In this tutorial we will show you how to install GCC Compiler on CentOS 7 Linux, as well as some extra required package by GCC