How to Install GCC 4.8 via PPA in Ubuntu 12.04, 13.04, 10.04

Last updated: August 26, 2013

Want GCC 4.8 with c++11 complete feature? Well here’s how to install it in Ubuntu 12.04, Ubuntu 13.04, Ubuntu 12.10 via the PPA.

The PPA provides both GCC 4.7.3 and GCC 4.8.1 for Ubuntu users. In this tutorial, you can follow below steps to upgrade gcc version in your system.

1.) Press Ctrl+Alt+T on your keyboard to open terminal. When it opens, run below commands to add the ppa:

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

2.) Then install gcc 4.8 and g++ 4.8:

sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8

3.) Once installed, run following commands one by one to use gcc 4.8 instead of previous version.

sudo update-alternatives --remove-all gcc 

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

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

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

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

Now you have the gcc 4.8 with c++11 complete feature in your system. Check out by:

gcc --version

gcc (Ubuntu 4.8.1-2ubuntu1~13.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.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

8 responses to How to Install GCC 4.8 via PPA in Ubuntu 12.04, 13.04, 10.04

  1. I used all your instructions
    in ubuntu 13.04 to install g++4.8. but when I wanted to compile a c++ program,for example world.cpp and I wrote g++ world.cpp I received:

    /usr/local/bin/ld: this linker was not configured to use sysroots
    collect2: error: ld returned 1 exit status

  2. Thank you man!!!!! works ,i was having problems white the codeblocks!!!
    Now Works Fine.

  3. Thank you very much. I have Ubuntu 12.04.2 32-bit and it worked flawlessly. I have installed Eclipse Kepler (version 4.3) and the first time I compiled a program it compiled it without any problems. When I tried to execute it, Eclipse showed me a panel where I have to chose the program to execute, showing me two alternatives, the second one with the suffix x64. I looked at the binaries folder and it appeared the compilation generated two versions, one for x86 (32-bit) and the other for x64 (64-bit). Of course, choosing the x64 version of the program to execute generated an error. When I choose the x32 version, the program executed without a glitch. When I tried to compile and execute a second program g++ did not generate the x64 version anymore. Now that I know this procedure works I am going to install it in my Ubuntu 12.04.3 64-bit, which I have installed separately in the same machine.

    Thank you again and nice work
    Ramiro

  4. Referring to my previous message, I want to signal some bizarre things that eventhough are not giving errors in the compilation or execution of C, C++ programs it is convenient to have an explanation because they are annoying. After I installed the gcc and g++ version 4.8.1-2 I saw the Update Manager telling me that there were:
    BEGIN QUOTE
    “Other udpates (LP-PPA-ubuntu-toolchain-r-test)”. Those updates refer to:
    GNU C preprocessor cpp-4.6
    GNU C++ compiler g++-4.6
    GNU C compiler gcc-4.6
    GCC, the GNU Compiler Collection (base package) gcc-4.6-base
    GNU Standard C++ Library v3 (development files) libstdc++6.4.6-dev
    Installed version: 4.6.3-1ubuntu5
    Available version: 4.6.4-1ubuntu1~12.4
    END OF QUOTE

    So I decide to reboot the machine. However, the same message above appears again. It is like Ubuntu does not realize that now gcc and g++ are in version 4.8.1-2.

    I want to post here some error messages I received while the installation process of 4.8.1 version:

    ramiro@Ramiro-Arias:~$ sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8
    Get:1 ‘http://security.ubuntu.com precise-security’ Release.gpg [198 B]
    :
    Ign ‘https://private-ppa.launchpad.net’ precise/main Translation-en
    Fetched 2,973 kB in 2s (1,159 kB/s)
    Reading package lists… Done
    W: A error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: ‘http://packages.medibuntu.org’ precise Release: The following signatures were invalid: NODATA 1 NODATA 2
    W: Failed to fetch ‘http://packages.medibuntu.org/dists/precise/Release’
    W: Some index files failed to download. They have been ignored, or old ones used instead.
    :

    The previous error appeared 5 times. There are more errors as follows:

    :
    ramiro@Ramiro-Arias:~$ sudo update-alternatives –remove-all gcc
    update-alternatives: error: no alternatives for gcc.
    ramiro@Ramiro-Arias:~$ sudo update-alternatives –remove-all g++
    update-alternatives: error: no alternatives for g++.
    :

    The version that I have installed is:

    ramiro@Ramiro-Arias:~$ g++ –version
    g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

    I would appreciate if you let us know how to resolve the issue with the Update Manager.
    Thanks in advance
    Ramiro

  5. hi.
    i use your PPA to update gcc compiler from 4.8.2 to 4.9 on ubuntu. but is does not update . need some help . thank you .

  6. error :non-static data member initializers only available with -std=c++11 or -std=gnu++11 [-Werror] int rows = numNodes/gridWidth;
    please help me am getting error , i have installed gnu++11

  7. @M: THANK YOU SO MUCH for the link you published!