Edited at

Ubuntu 14.04 に GCC 4.9 をインストールする

More than 3 years have passed since last update.


あらまし

GCC 4.9がUbuntu 14.04標準パッケージとして用意されていない。

PPAからインストールを行う。


PPAの追加

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


パッケージのインストール

sudo apt-get update

sudo apt-get install g++-4.9


update-alternatives の導入

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20

sudo rm /usr/bin/cpp
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-4.8 10
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-4.9 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++


バージョン確認

$ gcc --version

gcc (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3
Copyright (C) 2015 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 4.9.3-8ubuntu2~14.04) 4.9.3
Copyright (C) 2015 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.

$ cpp --version
cpp (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3
Copyright (C) 2015 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.


参考

Getting + installing gcc/g++ 4.9 on Ubuntu?

http://askubuntu.com/questions/428198/getting-installing-gcc-g-4-9-on-ubuntu

Choose gcc and g++ version

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

Handling the GNU Compiler Collection with debian alternatives

http://blog.renaud.io/2011/10/06/handling-the-gnu-compiler-collection-with-debian-alternatives/