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

被折叠的 条评论
为什么被折叠?



