查看GCC版本:
sudo dpkg -l | grep gcc
我的结果:
liz@LIZ:~$ sudo dpkg -l | grep gcc
[sudo] password for liz:
ii gcc 4:7.4.0-1ubuntu2.3 amd64 GNU C compiler
ii gcc-11-base:amd64 11.1.0-1ubuntu1~18.04.1 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-11-base:i386 11.1.0-1ubuntu1~18.04.1 i386 GCC, the GNU Compiler Collection (base package)
ii gcc-5 5.5.0-12ubuntu1 amd64 GNU C compiler
ii gcc-5-base:amd64 5.5.0-12ubuntu1 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-6 6.5.0-2ubuntu1~18.04 amd64 GNU C compiler
ii gcc-6-base:amd64 6.5.0-2ubuntu1~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-7 7.5.0-3ubuntu1~18.04 amd64 GNU C compiler
ii gcc-7-base:amd64 7.5.0-3ubuntu1~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-8 8.4.0-1ubuntu1~18.04 amd64 GNU C compiler
ii gcc-8-base:amd64 8.4.0-1ubuntu1~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii gcc-8-base:i386 8.4.0-1ubuntu1~18.04 i386 GCC, the GNU Compiler Collection (base package)
ii gcc-9 9.4.0-1ubuntu1~18.04 amd64 GNU C compiler
ii gcc-9-base:amd64 9.4.0-1ubuntu1~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii libgcc-5-dev:amd64 5.5.0-12ubuntu1 amd64 GCC support library (development files)
ii libgcc-6-dev:amd64 6.5.0-2ubuntu1~18.04 amd64 GCC support library (development files)
ii libgcc-7-dev:amd64 7.5.0-3ubuntu1~18.04 amd64 GCC support library (development files)
ii libgcc-8-dev:amd64 8.4.0-1ubuntu1~18.04 amd64 GCC support library (development files)
ii libgcc-9-dev:amd64 9.4.0-1ubuntu1~18.04 amd64 GCC support library (development files)
ii libgcc-s1:amd64 11.1.0-1ubuntu1~18.04.1 amd64 GCC support library
ii libgcc1:amd64 1:8.4.0-1ubuntu1~18.04 amd64 GCC support library
ii libgcc1:i386 1:8.4.0-1ubuntu1~18.04 i386 GCC support library
给不同GCC版本设置使用顺序(这里我优先使用GCC -5)
liz@LIZ:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 90
liz@LIZ:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 80
liz@LIZ:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
liz@LIZ:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60
liz@LIZ:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
查看设置好的GCC版本使用顺序:
liz@LIZ:~$ sudo update-alternatives --config gcc
下面是操作结果显示:
There are 5 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-5 90 auto mode
* 1 /usr/bin/gcc-5 90 manual mode
2 /usr/bin/gcc-6 80 manual mode
3 /usr/bin/gcc-7 70 manual mode
4 /usr/bin/gcc-8 60 manual mode
5 /usr/bin/gcc-9 50 manual mode
Press <enter> to keep the current choice[*], or type selection number:
GCC降级升级:
sudo apt install gcc-6 g++-6
ls /usr/bin/gcc*
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 90
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50
sudo update-alternatives --config gcc