52

This question already has an answer here:

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

results in...

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++?

Update:

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.

marked as duplicate by muru, user.dz, Eric Carvalho, iammilind, Community Jun 21 '16 at 4:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

45

check the repo page https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test

It shows version 5 as latest version so you'll not find 5.1 and thus result this error

you should install using (it still version 5 in your given Repository)

sudo apt-get install g++-5

Else if this doesn't work you can download the source code and compile it

  • 6
    This is the correct answer. However, I'd like to add that you may need to sudo ln -s /usr/bin/g++-5 to /usr/bin/g++ so you can call it directly with g++ – Trevor Hickey May 26 '15 at 6:26
  • By now 5.1 is in, too :) – abergmeier Jul 22 '15 at 7:48
  • 2
    g++-5 is g++-5.1. There was never a 5.0 release. I don't know why ubuntu stopped putting the minor version as part of the package name. – teeks99 Jul 23 '15 at 11:53
  • 1
    @TrevorHickey. this command "/usr/bin# ln -s /usr/bin/gcc /usr/bin/gcc-5 ln: failed to create symbolic link ‘/usr/bin/gcc-5’: File exists" not working...any idea how to do this linking operation? – Ashu Jan 24 '16 at 22:00
  • 1
    @Ashu sudo rm -f /usr/bin/gcc since it's already there, and then run the ln command again. – Trevor Hickey Jan 24 '16 at 23:05
38

Use the following command I found in here

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

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
4

Currently the ubuntu repo skips the minor version naming. When I installed the gcc-5 and g++-5 packages, the version that gets installed on my computer is 5.2.1. Well I feel it is as latest as you can get without compiling by yourself. So do not worry about the 5 it is the latest version.

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