I wish to install gcc 4.7 so that I can use some c++11 features.

I downloaded the source, ran ./configure and was told I needed GMP. Downloaded the code for that, hit ./configure and was told I needed m4. But I already have m4 (least that is what synamptic tells me).

What is going on and how can I fix it?


You can try this PPA for installing gcc 4.7. Do note that it has packages only for 12.04 and not for 11.10.

Run the following commands in a terminal:

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

Or, if you prefer a graphical way of installing a PPA, take a look at What are PPAs and how do I use them?.



You also most likely need to take care of g++-4.7

So the full commands list will be:

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

Also, don't forget to update-alternatives, as suggested here

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

This is confirmed to work in Ubuntu 12.04

  • g++ is a subset of gcc, no?
    – soandos
    Jul 2 '13 at 2:07
  • He and many others might be unaware, as I was. The thing is that in various distributions, once you install gcc, g++ got's installed automatically, with this ppa it's not the case and you need to install both separately.
    – user109764
    Jul 2 '13 at 8:57
  • 5
    This is definitely the right answer, the other one is incomplete I think...
    – Jonathan H
    Aug 13 '13 at 22:09
  • Then do this askubuntu.com/questions/269257/how-to-activate-gcc-4-7-version and repeat the same steps for G++. Feb 19 '16 at 8:27
  • Easiest way I think to activate gcc sudo rm /usr/bin/gcc sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc Sep 29 '19 at 2:40

Search the build directory for config.log files, and search those for the error message. That should give some clues.

BTW, if you don't need 4.7 precisely, you could try installing the gcc-snapshot package. That should have the features you need. It doesn't get installed in the standard place though, if I remember correctly.


This is a complete guide of how to build from sources gcc-4.7 on Ubuntu 12.04 64 bits:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.