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
🌐
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 --enablerepo=...
Author   zylon-ai
🌐
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 - To install all the packages belonging to a package group called “Development Tools” use the following command: # yum --setopt=group_package_types=mandatory,default,optional groupinstall "Development Tools" OR # yum --setopt=group_package_types=mandatory,default,optional group install "Development Tools" The yum has changed in Red Hat Enterprise Linux 7/CentOS 7. The package group “Development Tools”” has only the optional packages which by default doesn’t get installed. 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.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 11 › html › user_guide › chap-gcc
Chapter 2. GNU Compiler Collection (GCC) | User Guide | Red Hat Developer Toolset | 11 | Red Hat Documentation
To display the manual page for the version included in Red Hat Developer Toolset: $ scl enable devtoolset-11 'man gfortran' C++ Standard Library Documentation — Documentation on the C++ standard library can be optionally installed: # yum install devtoolset-11-libstdc++-docs ·
🌐
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 - To install the Development Tools including the GCC Compiler, run: Terminal · sudo yum group install "Development Tools" The command installs a bunch of new packages including gcc, g++ and make.
🌐
GitHub
gist.github.com › nchaigne › ad06bc867f911a3c0d32939f1e930a11
Building GCC 9.2.0 on CentOS 7 · GitHub
:) Unless you really need a version more recent that what is provided with the devtoolset. ... Great guide. To enable gcc 9 as default, may have to run the following commands: sudo yum install devtoolset-9-toolchain scl enable devtoolset-9 bash
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.

🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux › 8 › html › developing_c_and_cpp_applications_in_rhel_8 › additional-toolsets-for-development_developing-applications
Chapter 4. Additional toolsets for development | Developing C and C++ applications in RHEL 8 | Red Hat Enterprise Linux | 8 | Red Hat Documentation
Replace package_name with a space-separated list of packages to install. For example, to install the gcc-toolset-13-annobin-annocheck and gcc-toolset-13-binutils-devel packages: # yum install gcc-toolset-13-annobin-annocheck gcc-toolset-13-binutils-devel
🌐
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++”.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 11 › html-single › user_guide › index
User Guide | Red Hat Developer Toolset | 11 | Red Hat Documentation
$ scl enable devtoolset-11 'gcc -g -o fibonacci fibonacci.c' Copy to Clipboard Copied! ... This creates a new binary file called fibonacci in the current working directory. To install debugging information for a package that is already installed on the system: ... Copy to Clipboard Copied! ... Note that the yum-utils package must be installed for the debuginfo-install utility to be available on your system.
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 - 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....
🌐
Medium
medium.com › @ihouelecaurcy › how-to-check-and-install-gcc-on-linux-complete-developer-guide-98697e2ab78f
How to Check and Install GCC on Linux: Complete Developer Guide | by Ihouele Caurcy | Medium
July 24, 2025 - # Install GCC only sudo apt install gcc# Install complete development environment (recommended) sudo apt install build-essential# Verify installation gcc --version ... sudo yum install gcc # Or install complete development tools sudo yum ...
🌐
Linux Hint
linuxhint.com › install_gcc_build_tools_centos8
Installing GCC and C/C++ Build Tools on CentOS 8 – Linux Hint
YUM package manager should download all the packages from the internet and install them on your CentOS 8 machine. At this point, GCC and all the required C/C++ build tools should be installed.
Top answer
1 of 3
9

From this answer to "Install gcc 4.7 on CentOS [6.x]", the easiest way to get g++ 4.7, and the required tools and libraries, for CentOS 5.x is via the devtools package:

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools/devtools.repo 
yum --enablerepo=testing-devtools-6 install devtoolset-1.0

Since you're running g++ manually (as opposed to through make), you'll need to update your $PATH variable so your shell will use the new gcc, g++, etc. binaries:

export PATH=/opt/centos/devtoolset-1.0/root/usr/bin/:$PATH

At this point, your g++ should be version 4.7.0

$ g++ --version
g++ (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) 2012 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.

Be aware that installing gcc and associated tools and libraries in this manner relies on the repository maintainer to keep their packages up to date.

If you're interested in keeping your gcc up to date, you may want to consider building gcc from source.

Also, compiling programs with a different version of g++ and libstdc++ than are installed on your system can cause all kinds of Fun, coping with which is beyond the scope of this answer. It may be worth moving to a Linux distribution that has support for what you're doing.

2 of 3
1

Package managers are great, but (understandably) won't generally include the latest version of software. CentOS being a distribution particularly focusing on servers, favors stability (and extensive testing) over having the latest and shiniest. Here are your solutions:

Change distro

Other distributions like Arch Linux, Sabayon Linux or Debian "Sid" include newest versions a lot faster. You may consider changing distros.

Build it yourself

If you're stuck with CentOS, your best bet is to build gcc from source. It means getting the source code, making sure the dependencies are already present on your system (if not, I'm sure you can get them from the CentOS package manager), compiling the source into a binary executable, and installing the executable on your system.

It's not the easiest way to do it for sure, but you'll learn a lot about Unix in the process. Make sure to read the document a few times to make sure you get everything, and ask questions if something specific is unclear.

Be patient

At some point, this version (or newer) of gcc/g++ is going to enter the package manager. If you wait (up to several months, I'm not very familiar with the CentOS release cycle), you'll ultimately get what you want.

🌐
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 - ... Now that the update is done lets install the dependencies needed for the build.This is important you don’t want to wait to find one of the build dependencies were missing after 2hr’s of build · sudo yum -y install bzip2 wget gcc gcc-c++ ...
🌐
GNU
gcc.gnu.org › install
Installing GCC - GNU Project
This document describes the generic installation procedure for GCC as well as detailing some target specific installation instructions.
🌐
Red Hat
developers.redhat.com › articles › 2023 › 11 › 10 › install-gcc-and-build-hello-world-application-rhel-8
Install GCC and build a Hello World application on RHEL 8 | Red Hat Developer
November 10, 2023 - This command helps you discover the repositories containing GCC-related tools, ensuring you have access to the latest and most up-to-date resources for your development needs. This is a valuable feature for simplifying repository management. ... In this step, you will use a single command to download and install GCC 12.x and other development tools that are part of the Red Hat Developer Toolset.