12.04 - How to activate gcc 4.7 version?

  • Сашко Лихенко

    I have gcc 4.6.3 installed:

    gcc --version
    gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

    I have installed newer version:

    apt-get install gcc-4.7

    But i still get result "gcc 4.6.3" when I type gcc --version. How to fix it?

    I am using ubuntu 12.04 and i have done

    sudo apt-get update
    sudo apt-get upgrade
  • Answers
  • Rafał Cieślak

    This is because you have both versions installed, with 4.6 being treated as the default one.

    You can explicitly choose which one to use.

    $ gcc-4.7 --version
    gcc-4.7 (Ubuntu/Linaro 4.7.2-22ubuntu4) 4.7.2
    $ gcc-4.6 --version
    gcc-4.6 (Ubuntu/Linaro 4.6.3-15ubuntu3) 4.6.3

    The easiest way make gcc-4.7 the default gcc is to move the symlink of /usr/bin/gcc:

    sudo rm /usr/bin/gcc
    sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
  • Braiam

    please follow this instruction: Build gcc (Here: version: 4.7.2)

    tar -xf gcc-4.7.2.tar.bz2
    mkdir gcc-build
    cd gcc-build
    ../gcc-4.7.2/configure --enable-languages=c,c++
    make -j 4
    make install
    make clean          (OPTIONAL)
    cd ..

    Currently, the self-check of the gcc is not working, so this step is omitted here. Now you should check that the new compiler version 4.7.2 is called instead of the compiler used for the build process (here gcc-4.5.3). Enter the following commands:

    gcc --version; g++ --version

    The new compiler has been installed in /usr/local/bin. It is now the default compiler, because in the PATH variable /usr/local/bin is before /usr/bin.

  • Related Question

    How to update gcc to the latest version(in this case 4.7) in Ubuntu 10.04?
  • goldenmean

    I have Ubuntu 10.04 32-bit with gcc 4.4.3 currently installed on it. I want to upgrade it to gcc/g++ 4.7 (I am looking for C++ 0x support)

    How to update using Ubuntu Package Manager:

    apt-get upgrade/install ??

    As a second option I downloaded the latest gcc snapshot file from:


    Would doing

    make install 

    on this package build and install it from source?

  • Related Answers
  • hashtpaa


    Add the toolchain ppa test repository, then do apt-get update, and apt-get dist-upgrade

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    sudo apt-get update
    sudo apt-get install g++-4.7 c++-4.7

    This is only available in 12.04 - older ubuntu versions cannot be updated to this same version using this method.

    See here for further information about PPAs

  • ams
    sudo apt-get install gcc-snapshot

    Then, invoke it with:


    For the second part of the question, the answer is "yes, sort of". If you really want to do that (i.e. installing the gcc-snapshot package isn't enough) then you'll need to install the dependencies:

    sudo apt-get build-dep gcc-snapshot

    Then, find the correct configure options:

    gcc -v

    (and modify the install path etc.)

    Then, build like this:

    mkdir objdir
    cd objdir
    ../gcc-src-dir/configure ......insert..options..here...
    make install
  • Eliah Kagan

    10.04 LTS

    Use the following command to install add-apt-repository:

    apt-get install python-software-properties

    Then add the tooclain ppa test repo as described for 12.04 LTS.