How to install g++ 5.1 on Ubuntu desktop 15.04 64-bit?

I have not tested it on Ubuntu 15.04 but this is how I installed it on Ubuntu 14.04 from a PPA.

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

sudo apt-get update

sudo apt-get install gcc-5 g++-5
sudo update-alternatives 
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Alternatively you can download it and compile from source. I used to do that earlier, but it take a little bit more time.


The GCC 5.x suite is not available in 15.04. You can get it by adding a PPA, such as https://launchpad.net/~nicola-onorata/+archive/ubuntu/toolchain

I am not sure if this will result in it being the default compiler though, so you may still need to call it as g++-5or similar, to use it. You may also have some serious issues with linking to certain C++ libraries that are included in Ubuntu 15.04, as it does have some incompatibility with 4.9, primarily where STL is concerned.