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 gcc 4.6.3 installed:

gcc --version

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

I have installed newer version:

apt-get install gcc-4.7

But i still get result "gcc 4.6.3" when I type gcc --version. How to fix it?

I am using ubuntu 12.04 and i have done

sudo apt-get update
sudo apt-get upgrade
share|improve this question

3 Answers 3

up vote 5 down vote accepted

This is because you have both versions installed, with 4.6 being treated as the default one.

You can explicitly choose which one to use.

$ gcc-4.7 --version
gcc-4.7 (Ubuntu/Linaro 4.7.2-22ubuntu4) 4.7.2
[...]

$ gcc-4.6 --version
gcc-4.6 (Ubuntu/Linaro 4.6.3-15ubuntu3) 4.6.3
[...]

The easiest way make gcc-4.7 the default gcc is to move the symlink of /usr/bin/gcc:

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
share|improve this answer
1  
How to set gcc-4.7 default? –  Сашко Лихенко Mar 17 '13 at 21:30
    
@СашкоЛихенко Do you wish to just make gcc-4.7 the default gcc, or would you rather easily switch gcc between gcc-4.6 and gcc-4.7? –  Rafał Cieślak Mar 17 '13 at 21:34
    
I probably need it because I get the following error message installing Webkit application fom source. configure: error: Compiler GCC >= 4.7 or Clang >= 3.0 is required for C compilation –  Сашко Лихенко Mar 17 '13 at 21:35
    
@СашкоЛихенко This makes sense. GCC 4.7 introduces support for C++0x standard, which may be required by new software. –  Rafał Cieślak Mar 17 '13 at 21:36
    
I want to make gcc-4.7 the default gcc. Hope that helps –  Сашко Лихенко Mar 17 '13 at 21:37

If you are looking for installation of old version of gcc, then install directly from command line. For instance if you want install gcc-4.4.6, and latest available version is 4.7.3. If you type:

sudo apt-get install gcc

then by default latest version will be installed. To install gcc-4.4.6, just type:

sudo apt-get install gcc-4.4

But still your default compiler is latest gcc. To remove latest gcc as default type:

sudo rm /usr/bin/gcc

Now making gcc-4.4.6 as default compiler (this is replacement of gcc by gcc-4.4.x), type:

sudo ln -s /usr/bin/gcc-4.4 /usr/bin/gcc

Hope this will clarify above mentioned problem.

share|improve this answer

please follow this instruction: Build gcc (Here: version: 4.7.2)

tar -xf gcc-4.7.2.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.7.2/configure --enable-languages=c,c++
make -j 4
make install
make clean          (OPTIONAL)
cd ..

Currently, the self-check of the gcc is not working, so this step is omitted here. Now you should check that the new compiler version 4.7.2 is called instead of the compiler used for the build process (here gcc-4.5.3). Enter the following commands:

gcc --version; g++ --version

The new compiler has been installed in /usr/local/bin. It is now the default compiler, because in the PATH variable /usr/local/bin is before /usr/bin.

share|improve this answer

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.