Files

51 lines
2.3 KiB
Markdown

# GCC Compilers
!!! note
If you are looking for information about Intel compilers please check the [Intel Compilers](./intel_compilers.md) documentation.
RedHat provides multiple versions of the GCC compiler via the Software Collections (SCL) tool. This allows users to switch between different versions of GCC without affecting the system-wide default version. The different versions are provided via collections named "gcc-toolset-$GCC_MAJOR_VERSION".
Which GCC Toolset versions are available and which versions of GCC (and gcc tools they provide) can be found in the RedHat documentation:
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/developing_c_and_cpp_applications_in_rhel_9/assembly_additional-toolsets-for-development-rhel-9_developing-applications#gcc-toolset_assembly_additional-toolsets-for-development-rhel-9
To see which versions of the gcc-toolset are available on your system, you can use the following command:
```bash
[root@test ~]# dnf search gcc-toolset | egrep 'gcc-toolset-[0-9]+.x86_64'
Last metadata expiration check: 1 day, 7:28:21 ago on Wed 20 May 2026 06:28:36 AM CEST.
gcc-toolset-12.x86_64 : Package that installs gcc-toolset-12
gcc-toolset-13.x86_64 : Package that installs gcc-toolset-13
gcc-toolset-14.x86_64 : Package that installs gcc-toolset-14
gcc-toolset-15.x86_64 : Package that installs gcc-toolset-15
```
While having the package scl-utils installed, you can check which gcc-toolset versions are available on your system with the following command:
```bash
[root@test ~]# scl list-collections
gcc-toolset-12
```
After installing the desired gcc-toolset package, you can use the `scl enable` command to switch to the desired version of GCC for a single command or for the current shell session.
To use a specific version of GCC for a single command, you can use the following syntax (the `$COMMAND` needs to be one single argument string):
```bash
[root@test ~]# scl enable gcc-toolset-12 "$COMMAND"
```
or to spawn a new shell with the compiler ready:
```bash
[root@test ~]# scl enable gcc-toolset-12 bash
```
To load it into the current shell do (e.g. to be used in `~/.bashrc`):
```bash
source scl_source enable gcc-toolset-12
```
!!! note
In most cases we recommend to use the gcc version shipped with the RHEL version.