Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Could someone please tell me a sure-way of getting g++ and g++4.7 on to my Ubuntu? I have spent the whole day trying lots of sudo apt-get and nothing has worked.

When compiling from the IDE I am missing g++ as I get the compiler error:

“make[2]: g++: Command not found”

If I do:

sudo update-alternatives --config g++

it returns:

update-alternatives: error: no alternatives for g++.

If I do:

g++ --version

it returns:

The program 'g++' can be found in the following packages:
 * g++
 * pentium-builder
Try: sudo apt-get install <selected package>

I already have gcc 4.8 but I need g++ 4.7 (and possibly 4.8 if someone could advise me how I can download that?) because my code (which I did manage to compile with 4.7 earlier) is giving a compiler bug internal error.

(I havent been able to list every command I tried as there's been so many). There must be a way which definitely works


Have run to get g++ 4.6 so now when I call the g++ --version I get 4.6 showing. I then tried sudo apt-get install g++-4.7 to "upgrade" to 4.7 but this seemed to lose my g++ because I couldnt do g++ --version afterwards. I reverted back to 4.6. How can I upgrade to 4.7 and I really need to know how to get g++ 4.8?

share|improve this question
I have- which is how I originally found a g++ internal compiler error... which is what lead me to try and update to 4.8 (which now seems to have made my g++ disappear). – mezamorphic Nov 3 '13 at 23:40

If I have to guess, I will say that somehow your g++ symbolic link got damaged. A reinstallation of the g++ package should fix the issue:

sudo apt-get --reinstall install g++

Or, if you like doing things manually (you should try the above method first), you could:

If you have 4.6

sudo ln -i -s /usr/bin/g++-4.6 /usr/bin/g++

If you have 4.7

sudo ln -i -s /usr/bin/g++-4.7 /usr/bin/g++

If you have 4.8

sudo ln -i -s /usr/bin/g++-4.8 /usr/bin/g++
share|improve this answer
I will try the above now. I'd like to say thanks for continuing to help me- I really appreciate it. – mezamorphic Nov 3 '13 at 23:48
OK I tried the --reinstall command you wrote above and it worked to the extent that if I do g++ --version it now says I am using 4.6. WHen I try to see all versions I have via sudo update-alternatives --config g++ it doesn't work, still says no alternatives. Would you be able to tell me how I can install g++ 4.8 because I think I require this to get around the internal compiler bug I discovered when using 4.7? – mezamorphic Nov 3 '13 at 23:51
Worked out whats happening. When I go to install g++4.7 I seem to lose my g++ altogether. I use: sudo apt-get install g++-4.7 after your command... – mezamorphic Nov 4 '13 at 0:04
As far as I know, the gcc-4.x and g++-4.x packages do not automatically add themselves to the update-alternatives mechanism. You can add them manually using update-alternatives --install as described here -->… however I'm reluctant to post that as an answer since there are likely good reasons why that is not done by default. Or you can create the appropriate symlinks manually as described by @Braiam . – steeldriver Nov 4 '13 at 0:06
@steeldriver you beat it to me :( – Braiam Nov 4 '13 at 0:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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