多版本GCC安装及切换

ops/2024/9/25 21:30:58/

目录

  • 1 背景
  • 2 安装
    • 2.1 Ubuntu 20.04
    • 2.2 Ubuntu 18.04
  • 3 配置
  • 4 切换
    • 4.1 切换到版本9
    • 4.2 切换到版本10

1 背景

最近在研究C++20中的协程需要安装GCC版本10。用到GCC多版本切换,记录步骤。

2 安装

2.1 Ubuntu 20.04

运行如下命令安装两个版本编译器:

sudo apt install gcc-9 g++-9
sudo apt install gcc-10 g++-10

2.2 Ubuntu 18.04

默认安装最高版本gcc-7,添加Toolchain Test Builds PPA(个人软件包存档),它提供了GCC 10的最新版本

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

3 配置

使用update-alternatives命令配置多编译器版本:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10

说明:

  • gcc与g++版本绑定在一起了,修改gcc版本会同时修改g++版本

4 切换

使用如下命令切换编译器版本:

sudo update-alternatives --config gcc

4.1 切换到版本9

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-10   100       auto mode1            /usr/bin/gcc-10   100       manual mode2            /usr/bin/gcc-9    90        manual modePress <enter> to keep the current choice[*], or type selection number: 2

查看版本:

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0
Copyright (C) 2019 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.
$ g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0
Copyright (C) 2019 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.

4.2 切换到版本10

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-10   100       auto mode1            /usr/bin/gcc-10   100       manual mode2            /usr/bin/gcc-9    90        manual modePress <enter> to keep the current choice[*], or type selection number: 1

查看版本:

$ gcc --version
gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
Copyright (C) 2020 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.
$ g++ --version
g++ (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
Copyright (C) 2020 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.

http://www.ppmy.cn/ops/53008.html

相关文章

小程序onLoad 和 onShow

onLoad 和 onShow 是小程序页面的生命周期函数&#xff0c;它们在不同的时机触发&#xff0c;具有不同的用途和执行顺序 1.onLoad: &#xff08;1&#xff09;onLoad 在页面加载时触发&#xff0c;仅执行一次。 &#xff08;2&#xff09;用于页面的初始化操作&#xff0c;例如…

C++读写ini文件(window系统)

C++读写ini文件 一、ini文件说明1.1 INI文件的基本结构1.2 INI文件示例1.3 详细说明1.4 Ini文件使用场景二、C++代码读写INI文件2.1 C++ 读取INI2.2 C++ 写INI三、相关知识点3.1 WritePrivateProfileStruct 和 GetPrivateProfileStruct3.2 GetPrivateProfileInt一、ini文件说明…

MySQL备份与恢复

一、MySQL的数据库备份概述 1.数据库备份类型 (1)从物理与逻辑角度分类 物理备份可以分为冷备份&#xff0c;热备份和温备份。 冷备份&#xff1a;在数据库关闭状态下进行备份。 热备份&#xff1a;数据库处于运行状态下进行备份&#xff0c;备份方法依赖数据库的日志文件…

ComfyUI+PhotoMaker|一键创造个性化人物形象

ComfyUI和PhotoMaker&#xff0c;两款引领AI图像编辑潮流的软件&#xff0c;以其强大的功能和便捷的操作&#xff0c;深受广大艺术爱好者和专业人士的喜爱。本文将带你深入了解ComfyUI和PhotoMaker的结合使用&#xff0c;助你轻松打造个性化人物形象&#xff0c;让你的作品更加…

等保测评后的持续监控和安全运维体系建设

等保测评是中国特有的网络安全制度&#xff0c;旨在确保网络运营者履行安全保护义务&#xff0c;保障网络免受干扰、破坏或未经授权的访问。等保测评后的持续监控和安全运维体系建设是确保信息系统长期安全稳定运行的关键步骤。 持续监控 等保测评后&#xff0c;企业需要建立…

全国211大学名单及排名

序号 名称 省份 985 211 双一流 1 北京大学 北京 是 是 是 2 清华大学 北京 是 是 是 3 复旦大学 上海 是 是 是 4 上海交通大学 上海 是 是 是 5 浙江大学 浙江 是 是 是 6 国防科技大学 湖南 是 是 是 7 中国人民大学 北京 是 …

经典小游戏(一)C实现——三子棋

switch(input){case 1:printf("三子棋\n");//这里先测试是否会执行成功break;case 0:printf("退出游戏\n");break;default :printf("选择错误&#xff0c;请重新选择!\n");break;}}while(input);//直到输入的结果为假&#xff0c;循环才会结束} …

Docker 下载与安装以及配置

安装yum工具 yum install -y yum-ulits配置yum源 阿里云源 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo安装Docker 17.03后为两个版本&#xff1a; 社区版&#xff08;Community Edition&#xff0c;缩写为 CE&#x…