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 checked the gcc version on my system.

It is currently at 4.6.3. I read that gcc-4.8 is out.

I tried the following commands without success:

sudo apt-get install gcc (gcc is already the newest version)
sudo apt-get install gcc-4.8 (unable to locate package)

Does anyone know how to install this package on 12.04?

share|improve this question
    
@maggotbrain's answer worked for me, though I had to add: sudo apt-get install gcc-multilib as I was running into this issue: superuser.com/questions/432202/make-fails-compiling-gcc –  skillman May 6 '13 at 15:56
2  
Note to future googlers: If you get error message like undefined reference to `lexer_line' It is because of missing tools: bison and flex sudo apt-get install bison sudo apt-get install flex as pointed out here: http://stackoverflow.com/questions/4262531/trouble-building-gcc-4-6 –  virtualPN Jun 10 '13 at 18:56

4 Answers 4

up vote 77 down vote accepted

Is GCC-4.8 available for 12.04 Precise now?

Update: As of 6/05/2013, there is currently a release of gcc 4.8.1 for 12.04(precise) available at https://launchpad.net/~ubuntu-toolchain-r/+archive/test.

The short answer is: gcc-4.8 is currently available for 12.04(Precise) via the toolchain PPA or by compiling the source(see below for details).

Release Announcement

The announcement for the release of gcc-4.8 was made on March 22nd, so you probably won't be seeing this in an official repository just yet.

However, it appears that Launchpad does have a PPA available for the toolchain test builds that does include gcc-4.8, here: https://launchpad.net/~ubuntu-toolchain-r/+archive/test

According to the changelog and package list, there are debs for i386, amd64, arm, and powerpc and were built against raring 13.04.

The latest available version of gcc, for 12.04, is 4.8.1 and is available in the toolchain PPA.

Adding the toolchain/test PPA:

To add the PPA to your system, open a terminal(Ctrl+Alt+t) and run the following commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

You will also be prompted to install a number of suggested packages. These packages are recommended, but optional, for the installation of gcc-4.8.

What C++ features are available in gcc-4.8 that are not available in gcc-4.7.2?

  • According to GNU.ORG, gcc-4.7, supports a number of C++11 features.
  • As of the gcc-4.8 release, gcc-4.7 does not support 8 out of 64 features (See C++0x/C++11 Support in GCC)

  • These features are:

    Language Features
    - Rvalue references for *this
    - Generalized attributes
    - Alignment support
    - Inheriting constructors
    Concurreny
    - Bidirectional Fences
    - Memory model
    - Abandoning a process and at_quick_exit
    - Thread-local storage 
    
  • For a full list of changes in gcc-4.8, see the Changelist

I need these gcc features on 12.04 Precise, now. How can I get them?

Building GCC-4.8 from source:

If you need gcc-4.8 on 12.04 now, your only option is to build it from source.

Please read the GCC installation FAQ prior to installation.

You can download gcc-4.8 from one of gnu.org's mirror sites or directly from their SVN server.

Here is an example of steps to compile from source (see here for additional details.) Note that these may vary depending on your system and preferences.

  1. Download the source code

    • Make a build directory ( mkdir gcc-build && cd gcc-build)
    • Download the source file: wget http://www.netgull.com/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2 (adjust this command to use an appropriate mirror site.
    • Unzip the file (tar -xvjf <file name>)
  2. Install some additional libraries (sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev)

  3. Compile the source: ./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0
  4. Run make (This will take some time to complete. Go make some coffee, or bake some cookies. ;-))
  5. Install the code: sudo make install

Once this process has completed, run the command gcc --version to verify that the installation has completed successfully. You should see something similar to the following output:

maggotbrain@foucault:~$ gcc --version
gcc (Linaro 4.8.0) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The bottom line: Thank all those folks who provide easy to install Ubuntu backports for you. Give them some of the cookies that you baked while running make. ;-)

share|improve this answer
    
Excellent answer, except: E: Unable to locate package gcc-4.8 –  John Dibling Apr 4 '13 at 11:14
1  
Installing the additional libraries was not enough for me, but running ./contrib/download_prerequisites.sh fixed it (from stackoverflow.com/questions/9253695/…). –  Gauthier Oct 14 '13 at 15:11
7  
Note: I also had to install the package g++-4.8 (in addition to gcc-4.8) to be able to compile C++ code. Otherwise I was getting the compile error: gcc: error trying to exec 'cc1plus': execvp: No such file or directory 4.8. –  Boris Nov 6 '13 at 21:44
    
I was able to successfully install gcc4.8 on Precise –  Homunculus Reticulli Nov 10 '13 at 1:27
    
Doesn't work for me on amd64, libgcc1=1:4.8.1-2ubuntu1~12.04:i386 doesn't exist. –  pts Dec 18 '13 at 21:46

It should be built-in with Ubuntu 12.04. however, you can try this:

sudo apt-get update                    
sudo apt-get install gcc-4.8
share|improve this answer
8  
gcc 4.6.3 is the stock version in Ubuntu 12.04! –  user76204 Mar 23 '13 at 0:01

So answer above works, at least for manual install. Though even after sudo make install, running gcc still just runs the stock version 4.6.3. Even trying gcc-4.8 or gcc-4.8.0 doesn't work. Running /app/gcc/4.8.0/bin/gcc appears to be the only thing that works for me. I mean it is kind of lame but at least it works.

share|improve this answer
3  
[:facepalm:] Before you call things "lame" perhaps you should upgrade your operating systems knowledge. You could start with reading up on the concept of PATH: en.wikipedia.org/wiki/PATH_(variable) –  pszilard May 29 '13 at 20:37
    
Sure thing as well, as you do not install any package with DEBIAN/postinst script you have to set manually the default version to use by your system through the update-alternatives cmd. line ... If you used --prefix=/usr there is no need to meddle with PATH ... –  Antonio Mar 23 at 2:07

maybe symlinks are not updated after installation. You can run

ln -s /app/gcc/4.8.0/bin/gcc /usr/bin/gcc

and now gcc command will run 4.8 version.

share|improve this answer
1  
This not the way to go, update-alternatives is there in UNIX / Linux for a reason. –  Antonio Mar 23 at 2:10

protected by Community Aug 20 '13 at 12:02

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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