安装
linux 系统自带
原理
对命令创建软连接,切换的时候更改软连接
注意
可执行文件,比如gcc存在,需要删除,否则软连接会创建不成功
添加gcc软件版本
sudo update-alternatives --install /usr/bin/gcc gcc /home/opt/compiler/gcc-8.2/gcc-8.2/bin/gcc 8 --slave /usr/bin/g++ g++ /home/opt/compiler/gcc-8.2/gcc-8.2/bin/g++
sudo update-alternatives --install /usr/bin/gcc gcc /home/opt/compiler/gcc-12/bin/gcc 12 --slave /usr/bin/g++ g++ /home/opt/compiler/gcc-12/bin/g++
删除gcc软件版本
sudo update-alternatives --remove gcc /home/opt/compiler/gcc-8.2/gcc-8.2/bin/gcc
sudo update-alternatives --remove gcc /home/opt/compiler/gcc-12/bin/gcc
切换gcc版本
sudo update-alternatives --config gcc
其他用法
help一下