Upgrading GCC on CentOS 7.9

CentOS provides the Devtoolset toolchain, which allows for the easy installation and activation of newer GCC versions.

1. Install the SCL (Software Collections) repository

Execute the following command to enable SCL:

yum install centos-release-scl -y

2. Install the Devtoolset. If an error occurs, you can first replace the Aliyun source.

Taking the installation of GCC 7 as an example:

yum install devtoolset-7 -y

If you need other versions (such as GCC 8 or GCC 9), you can change it to devtoolset-8 or devtoolset-9.

3. Enable the new version of GCC

Temporary enable (only valid for the current terminal):

scl enable devtoolset-7 bash

4. Permanently enable the new version of GCC

If you want the new version to take effect automatically every time you log in, you can add the following content to the ~/.bashrc file:

source /opt/rh/devtoolset-7/enable

Then execute the following command to make the changes take effect:

source ~/.bashrc

5. Verify the GCC version

gcc --version

Leave a Comment