https://askubuntu.com/questions/26498/choose-gcc-and-g-version

https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu

https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/

关于 update-alternatives 命令的帮助:         http://www.cnblogs.com/welhzh/p/7339632.html

First erased the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

Install Packages

It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:

sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

Install Alternatives

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

Configure Alternatives

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Or switch using script:

#!/bin/sh

if [ -z "$1" ]; then
echo "usage: $0 version" 1>&2
exit 1
fi if [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then
echo "no such version gcc/g++ installed" 1>&2
exit 1
fi update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"

Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root:

apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:

update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

(Note the use of cpp-bin instead of just cpp. Ubuntu already has a cpp alternative with a master link of /lib/cpp. Renaming that link would remove the /lib/cpp link, which could break scripts.)

ubuntu 里切换 gcc,g++ 的版本的更多相关文章

  1. gcc/g++多版本切换 (ubuntu18.04)

    使用Ubuntu18.04已经有一段时间了,在使用过程中经常需要处理不同软件的编译工作,但是这时候就遇到这样一个问题,那就是不同软件,甚至是同一个软件的不同版本都会使用不同版本的gcc/g++来进行编 ...

  2. ubuntu 14.04 gcc/g++版本降低

    Matlab 2014a支持的gcc/g++版本是4.7x,而ubuntu 14.04以及更高版本默认安装的版本都是4.8及以上,因此需要降低gcc/g++版本,方法如下: 1 安装 $ sudo a ...

  3. Debian/Ubuntu 已安装gcc/g++ 4.8.1

    gcc 4.8.1 是第一个全然支持C++11(C++14非常可能在gcc 4.9.0開始支持.)的编译器,Windows上能够安装mingw版的.在sourceforge 上有下载.安装也比較方便. ...

  4. 通过yum升级gcc/g++至版本4.8.2

    最近在坐一个日期处理的问题,需要安装sxtwl模块,但是gcc版本4.7死活也安装不上,最后测试到只能升级gcc版本到4.8才得以解决 [root@123 bin]# gcc -vUsing buil ...

  5. ubuntu下切换默认的python版本

    Ubuntu系统自带python2.7(默认)和python3.5,所以不需要自己安装python.我们可以使用命令python -V或python3 -V来查看默认的python版本. 现在越来越多 ...

  6. ubuntu 18.04 gcc g++降级4.8版

    $ sudo apt-get install -y gcc-4.8 $ sudo apt-get install -y g++-4.8 $ cd /usr/bin $ sudo rm gcc $ su ...

  7. ubuntu 14.04 更新 gcc/g++ 4.9.2

    ubuntu 14.04 更新 gcc/g++ 4.9.2 最近看到c++11非常的好用,尤其是自带了regex,于是稍微学了一下c++11的新特性.可是我在编译一个regex程序是却发现稍微复杂一点 ...

  8. ubuntu 16.04 更新 gcc/g++ 4.9.2

    ubuntu 转载 2016年10月12日 :: 标签:ubuntu /g++ /gcc [html] view plain copy sudo dpkg -l g++ 最近在学C++primer , ...

  9. ubuntu下安装低级版本gcc/g++ 并随意切换

    来自:http://blog.sina.com.cn/s/blog_6cee149d010129bl.html 发现Android的版本中编译Host的程序经常因为本机的Gcc版本过高,需要这样那样的 ...

随机推荐

  1. ANDROID content provide 使用实例

    Content Provider提供了一种多应用间数据共享的方式,比如:联系人信息可以被多个应用程序访问.Content Provider是个实现了一组用于提供其他应用程序存取数据的标准方法的类. 下 ...

  2. 【转】在单片机中,C语言的一些误用和总结!

    在学习单片机的时候才真正知道C语言是什么,它是来干什么的~但是C语言用到嵌入式只是它小小的一部分应用,还有很多地方呢. 我们是不是在写程序的时候,错误很多就算编译通过了也达不到我们预期的结果,完了自己 ...

  3. python开启httpserver服务在自动化测试中的一个小运用

    httpserver可以在本机启动一个python实现的web服务器,在自动化测试中,可以将生成测试报告的目录开放给项目组同事. 先安装python 自动化测试框架,生成报告的目录D:\Automat ...

  4. A1082. Read Number in Chinese

    Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...

  5. 服务器内存占用不断的增加 & 任务管理器(PF使用率)不断的增加:关注句柄数

    最近一二个月以来,我发现服务器的内存占用正按着每天60M的速度增加. 一台windows 2003的服务器(2G内存),刚刚启起时占用内存:600M左右. 运行20天后,内存占用(PF使用):1.8G ...

  6. Log4j 2X 日志文件路径问题

    关于路径问题网上说啥的都有,但是也不能说人家错,只能说不适合你这个. 一开始,我用的   ${webapp.root} <RollingFile name="rollingFileSy ...

  7. Hadoop生态圈-基于yum源的方式部署Cloudera Manager5.15.1

    Hadoop生态圈-基于yum源的方式部署Cloudera Manager5.15.1 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我之前分享过关于离线方式部署Cloudera ...

  8. Redis危险命令重命名、禁用

    Redis的危险命令主要有: flushdb,清空数据库 flushall,清空所有记录,数据库 config,客户端连接后可配置服务器 keys,客户端连接后可查看所有存在的键 作为服务端的redi ...

  9. POJ 2796[UVA 1619] Feel Good

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case T ...

  10. DotNetBar 控件设置空内容时显示内容

    可以通过修改所有关于Watermark时的设置.