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

I have a 64 bit UBUNTU 13.04

running gcc --version shows me gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3

But on May 31 2013 gcc 4.8.1 was released . And I don't know how to install it ..

Can someone please explain me the steps that I need to do for successfull installation ..

Also please tell me whether I can have both the instances of gcc installed i.e 4.7.3 & 4.8. 1 or not ??

And after installation how can I point to the new gcc 4.8.1 ??

share|improve this question
    
I can't add comments in Ask Ubuntu yet, but I wanted to make a note to these answers in-case others trying to install GCC 4.8 run into the same issues as I did. When I got to the commends: sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++ I got the responses: update-alternatives: error: no alternatives for gcc update-alternatives: error: no alternatives for g++ On top of that, after running through the rest of the steps, running gcc --version still says its version 4.7, though 4.8 is installed. running ls -l /usr/bin/gcc* and ls -l /usr/bin/g++* shows th –  Ten_Ten_Steve Jul 14 '13 at 16:20
    
Why do you need this new version of GCC? –  Alvar Jul 15 '13 at 11:23
3  
@Alvar: 4.8 more or less completes implementation of c++-11 features and even adds features candidates of c++14 –  cheshirekow Aug 10 '13 at 14:09

3 Answers 3

up vote 20 down vote accepted

Use the mirrors listed Here and download the 4.8.1. The process is pretty straightforward. I would recommend to use this Procedure to complete your installation.

As you may know GCC doesn't support "make uninstall" and it has been suggested that you install GCC into a directory of its own and simply remove that directory when you do not need that specific version of GCC any longer. Hope this helped. Cheers

Edited: The Option 2:

I assume that you already have a former version of gcc, the easiest way could be adding PPA to your repositories and Update and upgrade you can have the latest version with no worries:

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

this will add the new PPA to the other sources.

Then unistall the alternative:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

then:

sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8

and as the alternative packages install :

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

at the end:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade

Hope this changes the --version ;)

share|improve this answer
    
Thanks for the reply Amir. But I already Googled that page & understood nothing .. I don't know which files should I download... Also the fact that you said to install gcc in a folder goes over my head as I don't know how to do that :( Can you please tell me step by step –  sud_the_devil Jun 25 '13 at 17:54
    
Check the edited version buddy ;) cheers –  Amir Jun 25 '13 at 18:42
    
Thanks for the effort Amir. After I enter sudo apt-get install gcc-4.8.1 . I get Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package gcc-4.8.1 E: Couldn't find any package by regex 'gcc-4.8.1' . Please help –  sud_the_devil Jun 26 '13 at 8:19
    
@sud_the_devil, did you be able to fix the issue using the edited version of my answer? If so, please "Accept" the answer so that the others could benefit in the future as well ;) –  Amir Aug 4 '13 at 22:48
    
Do you know of a PPA for Quantal/12.10? The packages in that PPA are currently broken. –  detly Oct 27 '13 at 22:49

do this exactly

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++ 
sudo apt-get update
sudo apt-get install g++-4.8 -y
sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
share|improve this answer
    
I did that exactly (copy and paste), but remove steps returned error: no alternatives for gcc and at the end the default is still the old g++ 4.7.3. New version is available with g++-4.8. –  Paul Jurczak Aug 21 '13 at 2:13

If you want to keep your old gcc, as I do, then do this instead:

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

Then to compile with older gcc, mine was 4.7:

gcc main.c

To compile with gcc 4.8:

gcc-4.8 main.c

You might find typing the extra -4.8 annoying, in which case follow the other answers given by raven and Amir. I quite like this method, as it gives me the choice to use a fall-back version (4.7) if I encounter a bug!

share|improve this answer
    
Thanks for this concise option. I want to point out that the apt-get install line should read: sudo apt-get install gcc-4.8 g++-4.8 The dash is needed there, and its absense might confuse a newbie. –  Justin W Nov 19 '13 at 22:05
    
@JustinW Opps I didn't even notice that typo –  user3728501 Nov 20 '13 at 15:09
    
@JustinW Is it fixed now? –  user3728501 Nov 20 '13 at 15:09
    
It's fixed, and upvoted! :) –  Justin W Nov 21 '13 at 21:14
    
@JustinW Aha, cheers mate! –  user3728501 Nov 22 '13 at 18:09

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.