How to upgrade GCC to 4.7+ on Ubuntu 12.04
Note: This is only needed on Ubuntu 12.04. Ubuntu 12.10 already comes with GNU C++ 4.7 and above.
Install
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7 g++-4.7
Update Alternatives
Add GCC 4.7
sudo update-alternatives --remove gcc /usr/bin/gcc-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
Make sure GCC 4.7 is the default alternative
sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc)
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-4.7 60 auto mode
1 /usr/bin/gcc-4.6 40 manual mode
2 /usr/bin/gcc-4.7 60 manual mode
Press enter to keep the current choice[*], or type selection number: 0