ubuntu多个版本gcc并存使用

这篇博客介绍了如何在Ubuntu系统中安装多个GCC版本,包括gcc5、gcc7、gcc9和gcc10,并详细说明了如何通过更新源、安装、设置优先级以及切换不同版本的方法,确保不同版本的GCC可以共存并方便切换使用。

Ubuntu安装多个版本gcc

我们在不同的环境下需要使用不同的GCC版本,同时还要保证不同版本的GCC共存。下面列出几个版本的安装方式:

gcc5

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5 g++-5

gcc7

sudo add-apt-repository ppa:jonathonf/gcc-7.1
sudo apt-get update
sudo apt-get install gcc-7 g++-7

gcc9

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-9 g++-9

gcc10

sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
sudo apt update
sudo apt install gcc-10 g++-10 

将多个版本的gcc加入到选项中

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 (此优先级高,默认使用gcc-7)

使用下面命令进行切换

sudo update-alternatives --config gcc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值