Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to compile my program with the latest version of gcc.

Ubuntu 14.04 comes with gcc 4.8.2, however there's 4.9.0 available, moreover, I see that it is available as a package: gcc-4.9. I tried to install it

sudo apt-get install gcc-4.9

but it says

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'gcc-4.9-base' for regex 'gcc-4.9'
gcc-4.9-base is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Looks like it is already installed, just not as the default one? How do I utilize it to build my program?

share|improve this question
    
If you want to install gcc-4.8 , you need to use sudo apt-get install gcc-4.8. gcc-4.9 ,gcc-4.8 , gcc-4.7, gcc-4.6 all are in Ubuntu main repo. –  user224082 May 16 '14 at 1:18
    
@Dumindu But how do I use gcc-4.9 specifically? –  Nickolai Leschov May 16 '14 at 2:33
    
Uninstall others and install 4.9. –  user224082 May 16 '14 at 3:55
    
@Dumindu Wait, did you just tell me to do what I just did? It is not working. –  Nickolai Leschov May 16 '14 at 17:53
    
switch to root user : sudo su - goto /usr/bin then run ls -l gcc* and post your output. then I'll post your answer. –  KasiyA Aug 14 '14 at 9:46

3 Answers 3

The best way to correctly install gcc-4.9 and set it as your default gcc version use:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

The --slave, with g++, will cause g++ to be switched along with gcc, to the same version. But, at this point gcc-4.9 will be your only version configured in update-alternatives, so add 4.8 to update-alternatives, so there actually is an alternative, by using:

sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

Then you can check which one that is set, and change back and forth using:

sudo update-alternatives --config gcc

NOTE: You could skip installing the PPA Repository and just use /usr/bin/gcc-4.9-base but I prefer using the fresh updated toolchains.

share|improve this answer
    
Thanks for the edit @muru ...like I said below, I was up for about 3 days very tired and update-alternatives does requires sudo and I think I forgot the (--) before slave. :) So, Thank you. –  Sudo SU Root Feb 15 at 17:16

Use the Toolchain Test Builds PPA:

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

I don't think GCC 4.9 is fully available for Ubuntu 14.04 yet. The base package (gcc-4.9-base) and the GCC Go 4.9 compiler (gccgo-4.9) are available, but the other frontends are not. I don't know why.

share|improve this answer
    
@SudoSURoot it may or may not be set as default, that's not my concern (there are other posts dealing with that). However, that GCC 4.9's C and C++ frontends can be installed on 14.04 purely from the official repositories is patently false, since the gcc-4.9-base package does not and will not contain a binary frontend. –  muru Feb 14 at 22:18
    
You are correct about the base package. As you'll see in my answer, I used the PPA. I posted the comment first, then answered the question as stated, from question... Because simply adding the PPA and installing 4.9 does not enable it which is needed to "use gcc 4.9". I should have deleted the comment after I answered the question. I apologize. My answer is what should be focused on. I jumped to conclusions... and commented to fast. I am actually pretty new with using 14.04 since I got me dedicated server. I'm gong to make sure I didn't down vote and I'll fix it if I did. –  Sudo SU Root Feb 14 at 22:28
    
@SudoSURoot alright. Even so, unless OP has a problem with calling gcc-4.9 or g++-4.9 instead of gcc or g++, I will stick to not updating the alternatives. –  muru Feb 14 at 22:31
    
I totally understand. I build Android systems though, which uses a lot of $(which gcc) and $(which g++) etc... So I always have to have defaults set to the version I want to use. Some of my kernel code wouldn't compile with host gcc-4.8 so I had to update. I just repeated what worked for me. Thanks for reminding me though... Like I said in my edit, from last comment, I may have down voted, prematurely, if so I'll fix it. I had been up for 2 or 3 days working on my kernel source when I posted these. Everyone has their ways... I just found the more thorough my answer the less questions I g –  Sudo SU Root Feb 14 at 22:40

To call gcc 4.9 specifically, use gcc-4.9 at the command prompt.

All the gcc versions you have installed can be called individually by adding a hyphen and the version number at the end of gcc. In your case, gcc-4.8 and gcc-4.9 should be available. In a terminal, type gcc- (note the hyphen) and the push tab twice to see if there are any other versions installed.

Note that the default gcc is likely still 4.8. (Use gcc -v to verify this.) Unfortunately changing the default is not trivial if you installed gcc-4.9 from the default repository as it did not add a update-alternatives entry. If you are interested in how to change the default, see answers to this this question.

share|improve this answer
    
How do I make a project relying on makefile and possibly other build infrastructure build with gcc-4.9 instead of gcc? –  Nickolai Leschov Jul 13 '14 at 13:41
    
The best way to make sure gcc-4.9 is used across build systems is to change the default gcc. Follow the link I provided in my answer for how to do this. Alternatively you could create a symbolic link, though I recommend against this except as last resort since the package manager might complain when updating gcc. If you insist: sudo rm /usr/bin/gcc; sudo ln -s /usr/bin/gcc-4.9 /usr/bin/gcc. To revert to gcc-4.8 default, just replace gcc-4.9 with gcc-4.8. You may have to do this with g++ and other GNU compilers as well. –  holocronweaver Jul 13 '14 at 20:29
    
GCC 4.9 is not available in Ubuntu 14.04 (except for the GCC Go compiler), so while this answer will probably work in Ubuntu 14.10, it doesn't help now. :-) –  Søren Løvborg Aug 2 '14 at 17:43
    
Actually it is available in Ubuntu 14.04, though it may have been a mistake: packages.ubuntu.com/trusty/gcc-4.9-base. I have been using it since April. –  holocronweaver Aug 3 '14 at 11:46

Your Answer

 
discard

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.