This question always bothers me! Last time for 4.9 I tried the commands mentioned in this answer for g++4.9. The same trick doesn't work now:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5.1 g++-5.1
E: Unable to locate package gcc-5.1
E: Couldn't find any package by regex 'gcc-5.1'
E: Unable to locate package g++-5.1
E: Couldn't find any package by regex 'g++-5.1'
What is the correct command for directly installing the latest g++ in Ubuntu? Is there any magic command which works uniformly for all the updates of g++?
I found that the correct command to install it is:
sudo apt-get install g++-5
This works now! Though in the GCC official page, the version is 5.1.