Loading

ubuntu 22.04 安装多个gcc

1、查看默认gcc版本信息:

pi@raspberrypi:~/software$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2、安装gcc-12

sudo apt update
sudo apt install gcc-12 g++-12  # 22.04+ 版本通常直接支持

现在默认gcc信息:

pi@raspberrypi:~/software$ gcc --version
gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

3、多版本切换和管理

使用 update-alternatives 创建多版本管理:

# 注册 GCC 11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 120 \
--slave /usr/bin/g++ g++ /usr/bin/g++-11 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-11

# 注册 GCC 12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 110 \
--slave /usr/bin/g++ g++ /usr/bin/g++-12 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-12

切换gcc版本:

sudo update-alternatives --config gcc
posted @ 2025-07-30 15:40  eiSouthBoy  阅读(120)  评论(0)    收藏  举报