如何通过PPA安装/升级gcc和g++版本到4.8.1 (Ubuntu 12.04, 13.04, 10.04适用)

时间:2021-02-08 06:55:31

gcc 4.8.1 是第一个完全支持C++11 的编译器。下文是如何在Ubuntu 12.04, Ubuntu 13.04 或 Ubuntu 12.10中通过PPA安装GCC 4.8的步骤。PPA为Ubuntu用户提供了GCC 4.7.3 和 GCC 4.8.1两个版本。在Ubuntu12.04 LTS默认安装的是gcc4.6.3,该版本只支持部分c++11的特性,可以通过增加“-std=c++0x" 编译选项来使用这些特性,但是对多线程库的支持较差。你可以参考下文的步骤,来升级系统中的gcc,g++版本。


安装步骤:

1) Ctrl+Alt+T打开终端,执行如下命令adding PPA to your repositories:

test@test:/install$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test


2) 安装gcc 4.8 和 g++ 4.8

test@test:/install$ sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8


3) 装完后,依次执行如下命令将系统默认的gcc,g++编译器版本设置为4.8版本

test@test:/install$ sudo update-alternatives --remove-all gcc

update-alternatives: error: no alternatives for gcc.

test@test:/install$ sudo update-alternatives --remove-all g++

update-alternatives: error: no alternatives for g++.

test@test:/install$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20

update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in auto mode.

test@test:/install$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20

update-alternatives: using /usr/bin/g++-4.8 to provide /usr/bin/g++ (g++) in auto mode.

test@test:/install$ sudo update-alternatives --config gcc

There is only one alternative in link group gcc: /usr/bin/gcc-4.8

Nothing to configure.

test@test:/install$ sudo update-alternatives --config g++

There is only one alternative in link group g++: /usr/bin/g++-4.8

Nothing to configure.


4) 安装完毕。现在你的系统中已经默认使用gcc 4.8和g++ 4.8了。通过如下命令查看:

test@test:/install$ g++ --version

g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

Copyright (C) 2013 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.


test@test:/install$ gcc --version

gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

Copyright (C) 2013 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://ubuntuhandbook.org/index.php/2013/08/install-gcc-4-8-via-ppa-in-ubuntu-12-04-13-04/