12

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
0

3 Answers 3

13

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
10
  • 2
    How to set gcc-4.7 default? Mar 17, 2013 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? Mar 17, 2013 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, 2013 at 21:35
  • @СашкоЛихенко This makes sense. GCC 4.7 introduces support for C++0x standard, which may be required by new software. Mar 17, 2013 at 21:36
  • I want to make gcc-4.7 the default gcc. Hope that helps Mar 17, 2013 at 21:37
0

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.

-1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .