yum install centos-release-scl-rh
yum install devtoolset-3-gcc devtoolset-3-gcc-c++
update-alternatives --install /usr/bin/gcc-4.9 gcc-4.9 /opt/rh/devtoolset-3/root/usr/bin/gcc 10
update-alternatives --install /usr/bin/g++-4.9 g++-4.9 /opt/rh/devtoolset-3/root/usr/bin/g++ 10
Answer from Lars Bilke on Stack Overflowyum install centos-release-scl-rh
yum install devtoolset-3-gcc devtoolset-3-gcc-c++
update-alternatives --install /usr/bin/gcc-4.9 gcc-4.9 /opt/rh/devtoolset-3/root/usr/bin/gcc 10
update-alternatives --install /usr/bin/g++-4.9 g++-4.9 /opt/rh/devtoolset-3/root/usr/bin/g++ 10
For installing the system compilers gcc, g++, the install command is # yum install gcc-c++ → Provides version 4.8.5 : /usr/bin/{ gcc, g++ }.
Other options: 1. gcc53-c++-5.3.0-1.el6.x86_64.rpm → https://drive.google.com/file/d/0B7S255p3kFXNRm9FVnZYUnhyZzg/view?usp=sharing&resourcekey=0-1N6zQa6Sbl_WycG1O9I7JA : Download and install : # cd Downloads/ && yum install ./gcc53-c++-5.3.0-1.el6.x86_64.rpm ..... Provides /usr/bin/{gcc53, g++53}.
- The devtoolset´s : https://www.softwarecollections.org/en/scls/rhscl/devtoolset-6/ →
# yum-config-manager --enable rhel-server-rhscl-7-rpms
Install gcc, g++ version 4.9.2 : # yum install devtoolset-3-gcc-c++
Note : You can have as many gcc/g++ versions as you want, installed at the same time. ( The system compilers are a must.)
- gcc49-c++-4.9.3-1.el6.x86_64.rpm https://drive.google.com/file/d/1Pwq1ua80dGM72i7rpDNAIIdfcR1WK-hG/view?usp=sharing → Provides
/usr/bin/{gcc49, g++49}.
gcc63-c++-6.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1t4WrgvpEP-6_NN3qMJhz9MS3CJhHrHKc/view?usp=sharing → Provides
/usr/bin/{gcc63, g++63}.gcc45-c++-4.5.4-1.el7.x86_64.rpm https://drive.google.com/file/d/15aRg-BPhuyaEyZA9Jy-iAyC21_pwN7nD/view?usp=sharing → Provides
/usr/bin/{gcc45, g++45, gfortran45}gcc42-c++-4.2.4-1.el6.x86_64.rpm https://drive.google.com/file/d/1eYWk6Nd63xeqqAUoJldNWRuwEGO6cAyv/view?usp=sharing → Provides
/usr/bin/{gcc42, g++42}
gcc73-c++-7.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1PgwCP5tu8D0EJbJVTqJd7Vg8dJ4l4noi/view?usp=sharing → Provides
/usr/bin/{gcc73, g++73}gcc48-c++-4.8.5-1.el6.x86_64.rpm https://drive.google.com/file/d/1w6fW6oSflDDYZt_cOpGj3QMEmzUC8Q9L/view?usp=sharing → Provides
/usr/bin/{gcc48, g++48, gfortran48}gcc84-c++-8.4.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1xgFtsiDi2uiB1B0AcOaSpxVizzET-pJf/view?usp=sharing → Provides
/usr/bin/{gcc84, g++84, gfortran84}
You will have to do it the old fashioned way. Get the GCC sources, build it by hand.
Any reason you are averse to doing this? (I can think of a few, but unless you do too, I don't want to add anything that might be confusing).
If you are hesitant to build from sources, I can probably provide some steps.
NOTE: The reason for that is the devtools with 4.9 is currently only available to Red Hat users with a valid license. Wait for a while, and eventually I am sure 4.9 devtools will be made available to CentOS users too like 4.8 is currently.
CentOS 6/7 officially supports this. You don't need third party repository. And gcc version is 4.9.2 in CentOS's repo.
yum install centos-release-scl-rh
yum install devtoolset-3-gcc devtoolset-3-gcc-c++
To use the updated tools, start a new shell using the scl command:
scl enable devtoolset-3 bash
You may also need to reset your PATH environment variable, which might be set in ~/.bashrc or other profile file. If you need to change it, it should point to /opt/rh/devtoolset-3/root/usr/bin/:$PATH
More information on the SCL from CentOS and from Red Hat
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
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 executeexittwice to exit the opened shell window, which verifies that thesclcommand 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~/.bashrcprofile, 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.