GCC版本切换

update-alternatives --config gcc

  1. $ update-alternatives --config gcc
  2. There is only one alternative in link group gcc (providing /usr/bin/gcc): /usr/bin/gcc-9
  3. Nothing to configure.

sudo update-alternatives --install needs <link> <name> <path> <priority>

  1. $ sudo update-alternatives --install /usr/bin/gcc gcc /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0_2/bin/gcc-11 100
  2. $ sudo update-alternatives --install /usr/bin/g++ g++ /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0_2/bin/g++-11 100
  1. $ gcc -v
  2. -bash: /usr/bin/gcc: Is a directory
  1. update-alternatives --config gcc
  2. There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. * 0 /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0_2/bin/gcc-11 100 auto mode
  6. 1 /home/linuxbrew/.linuxbrew/Cellar/gcc/11.2.0_2/bin/gcc-11 100 manual mode
  7. 2 /usr/bin/gcc-9 40 manual mode
  8. Press <enter> to keep the current choice[*], or type selection number:

sudo update-alternatives --remove <name> <path>

  1. $ sudo update-alternatives --remove gcc /home/linuxbrew/.linuxbrew/Cellar/gcc/