ubuntu20.04 切换 gcc/g++ 版本

ubuntu20.04 切换 gcc/g++ 版本

如果要切换到低版本5.4

通过命令查询本机gcc/g++已安装的版本

复制代码
ls /usr/bin/gcc*
ls /usr/bin/g++*
复制代码
sudo gedit /etc/apt/sources.list

在文件尾部添加如下源,然后保存并更新

复制代码
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

sudo apt-get update

安装gcc/g++ 5.4

  • 查看gcc5可选的版本

    sudo apt-cache policy gcc-5

安装其中一个版本

复制代码
sudo apt-get install gcc-5=5.4.0-6ubuntu1~16.04.12

g++ 安装类似

复制代码
sudo apt-cache policy g++-5
sudo apt-get install g++-5=5.4.0-6ubuntu1~16.04.12
  • 版本切换

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 40
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
    sudo update-alternatives --config gcc

选择gcc-5对应的编号 回车即可

g++ 类似

复制代码
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50
sudo update-alternatives --config g++

选择g+±5对应的编号 回车即可

切换回高版本方法类似

相关推荐
ltl5 小时前
大多数「无锁」代码其实不是无锁的
linux
ltl5 小时前
Linux 内核的内存屏障:一个让我调了三天的 bug
linux
Lonely 净土7 小时前
Rocky Linux 安装教程
linux·运维·服务器
啊啊啊啊啊!!!!9 小时前
【c++】stack和queue的接口使用以及底层实现
开发语言·c++
李白你好11 小时前
Windows 离线 Linux 提权辅助查询工具
linux
(Charon)12 小时前
【C++】锁与原子操作(四):自旋锁的完整实现与性能优化
c语言·开发语言·c++
Lust Dusk12 小时前
记一次Linux应急响应题目解析
linux·运维·服务器·网络·安全·网络安全
ShineWinsu13 小时前
对于Linux:五种IO模型以及非阻塞IO的详细解析
linux·c++·面试·io·阻塞·非阻塞·fcntl
千千寰宇13 小时前
[Linux/Ollama] Termux : 一款运行在 Android 平台上的开源终端模拟器与 Linux 环境应用、支持在手机上基于Ollama部署LLM
linux
呜喵王阿尔萨斯13 小时前
extern “C“ in C++
c语言·c++·算法