Try   HackMD

Switch GCC/G++ version for linux (Debian/Kali)

Author: Junner
Date: 2/26/2025

Solution Ref: https://unix.stackexchange.com/questions/410723/how-to-install-a-specific-version-of-gcc-in-kali-linux

When I'm building gf2x for NTL, it failed:

C++ style comments are not allowed in ISO C90

And I found the version with gcc -v

gcc version 14.2.0 (Debian 14.2.0-8)

My version is 14.2.0 at my Kali machine. We need to change it to a hopeful version.

Luckily, the building task works at my Pop!_OS machine, and the version is:

gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)

For installing a certain version of GCC/G++, the command is simple:

sudo apt install gcc-11 g++-11

Set GCC priority of selecter: (the bigger number, the higher priority)

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 2 --slave /usr/bin/g++ g++ /usr/bin/g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 1 --slave /usr/bin/g++ g++ /usr/bin/g++-14

And run this to select which version you want to use now.

update-alternatives --config gcc
​​​​There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

​​​​  Selection    Path             Priority   Status
​​​​------------------------------------------------------------
​​​​  0            /usr/bin/gcc-11   2         auto mode
​​​​  1            /usr/bin/gcc-11   2         manual mode
​​​​* 2            /usr/bin/gcc-14   1         manual mode

​​​​Press <enter> to keep the current choice[*], or type selection number:

For my example, I typed 1 to select the target version.