Location>code7788 >text

Managing GCC versions with update-alternatives

Popularity:138 ℃/2024-07-29 14:22:18

catalogs
  • synopsis
  • course of action

synopsis

When more than one version of GCC exists in the operating system, you can use a program that uses theupdate-alternativesManages the compiler version used by default.

This article usesgcc-9cap (a poem)gcc-11To do the demo, the operating system is ubuntu-20.04.

course of action

①Confirm with the following commandgccCorrectly installed

gcc-9 --version
gcc-11 --version

② Use the following command to view the configuredgccreleases

update-alternatives --display gcc

Not configured should output the following:

③Add version to update-alternatives

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110

Here 90 and 110 are the specified priorities.

Configuration Defaultsgccreleases

update-alternatives --config gcc

After executing this command, the system will provide a list of choices and we can select the defaultgccreleases

I have the highest priority heregcc-11is automatically selected as the default version, we can just type enter to select it (depending on your actual situation)

Validating Changes
Run the following command to make sure the changes take effect, the version displayed should match the one you chose

gcc --version