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 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 at 1:18
    
@Dumindu But how do I use gcc-4.9 specifically? –  Nickolai Leschov May 16 at 2:33
    
Uninstall others and install 4.9. –  user224082 May 16 at 3:55
    
@Dumindu Wait, did you just tell me to do what I just did? It is not working. –  Nickolai Leschov May 16 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 at 9:46

3 Answers 3

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

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 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 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 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 at 11:46

If you have not already done so, install the Synaptic Package Manager.

sudo apt-get update
sudo apt-get install synaptic

You can find Synaptic Package Manager in the dash. Open Synaptic. In the search field, enter gcc-4.9-base, if not already installed, mark it for installation. If you do a version check for gcc it will read 4.8.2 which includes the 4.9 base.

gcc --version

Most software downloads will contain either a readme file or "INSTALL" (Zsh and others). These files will contain detailed instructions on the steps to go through.

If you want an adventure download the tar files for Zsh from zsh.org. Read the install file, but be prepared to be at your computer for some time because the process is lengthy compared to using Software Center.

The basic commands and the order in which they are executed will be laid out in detail in the INSTALL file. Zsh uses the G++ compiler, which is part of the "build-essential" package. (also contains other needed dependencies and C type compilers.

To get build-essential

sudo apt-get update

sudo apt-get install build-essential

The basic commands you will use, these will access the compiler, are:

./configure

Make

Makefile

But, again, readme and INSTALL files from the publisher will usually have all the instructions, it will have all the specifics and howto's.

By the way, Zsh is available through SoureForge.org.

Enjoy.

share|improve this answer
1  
This does not answer the question posed. –  holocronweaver Jul 12 at 19:10
    
@holocronweaver The commands are used by the GCC compiler, and yes, it is the answer you were looking for. GCC understands these commands if the installation files are available to configure, make and install. Thanks for the down vote. –  RCF-U14.04 Jul 12 at 22:46
    
The question asks how to use gcc-4.9 when gcc-4.8 is installed. Your answer does not ever mention compiler versions. –  holocronweaver Jul 12 at 23:40
    
@holocronweaver why don't you answer it yourself. –  RCF-U14.04 Jul 12 at 23:52
    
GCC 4.8.2 includes the GCC 4.9 base according to the Synaptic package manager. –  RCF-U14.04 Jul 13 at 0:03

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.