在 Debian 系统上,GCC 可以同时安装多个版本,官方并没有限制“只能装几个”,实际数量取决于:
Debian 不同发行版自带不同 GCC 版本,例如:
testing / unstable 或 apt 第三方源装更新的(gcc-13、gcc-14 等)你可以同时安装:
sudo apt install gcc-9 gcc-10 gcc-11 gcc-12
update-alternatives 管理装多个版本后,用:
sudo update-alternatives --config gcc
来切换默认 gcc 指向哪个版本。
除了 apt,你还可以从源码编译安装任意版本到 /opt/gcc-x.y:
/opt/gcc-13/bin/gcc
/opt/gcc-14/bin/gcc
理论上可以装无数个,只要磁盘够。
libstdc++ 可能冲突(用 update-alternatives 或指定路径避免)Debian 上 GCC 能装多个版本,数量无上限,推荐用 apt +
update-alternatives管理,需要更多就源码装到独立目录。
如果你告诉我 Debian 版本 + 需要的 GCC 版本,我可以给你具体安装命令。