Switching
8. Switching System GCC
Finally, to easy Managing GCC Versions use update-alternatives
So first install the New GCC 12.2.x with, for instance:sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/x86_64-pc-linux-gnu-gcc-12.1.0 10
In case, replace 12.2.0 with your current version in the above Command.
To check it run:ls /usr/local/bin | grep gcc-12
The grep Command refine the output List showing only the Entries matching the Keyword.
And then the to Setup also the System GCC use:sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 20
Next to Switch between GCC Versions play:
sudo update-alternatives --config gcc
Last, to test the GCC in use:
gcc -v

Congratulations, your GCC 12.2 should be now nicely working on Ubuntu 22.04. Good Luck! :)