- 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-alternatives
Manages the compiler version used by default.
This article usesgcc-9
cap (a poem)gcc-11
To do the demo, the operating system is ubuntu-20.04.
course of action
①Confirm with the following commandgcc
Correctly installed
gcc-9 --version
gcc-11 --version
② Use the following command to view the configuredgcc
releases
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 Defaultsgcc
releases
update-alternatives --config gcc
After executing this command, the system will provide a list of choices and we can select the defaultgcc
releases
I have the highest priority heregcc-11
is 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