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.

So I'm working on a project and I wanted to use some C11 features for C. To use those features GCC 4.7 is required, so I went to synaptic and looked up 4.7, and I found the packages gcc-4.7-base so I installed it[1].

So now that gcc-4.7-base is installed I expected to be able to use 4.7, but no, when I do gcc --version it still shows 4.6.3 even more, when I try to directly call 4.7(via /usr/bin/gcc-4.7) it doesn't exist, though a gcc-4.6 executable does exist.

How do I "activate" GCC 4.7? I read here, you do some crazy stuff with update-alternatives, but it doesn't work for me as the gcc-4.7 executable doesn't actually exist on my machine.

Notes: 1. I also saw gcc-4.6-base, so I figured I'd uninstall it, but synaptic attempted to remove every package I had installed and install a Java runtime, so for obvious reason I decided not to remove it.

share|improve this question
add comment

2 Answers

The following worked for me.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

Source for reference

share|improve this answer
add comment

I'm not sure what the gcc-4.7-base package is for, on Ubuntu 12.04 as it doesn't contain the new gcc-4.7 compiler. It just contains a copyright file and a TODO list.

On Ubuntu 12.04 the gcc-4.7-base package which was installed via

apt-get install gcc-4.7

did not contain any

crc@bork:~$ dpkg --contents /var/cache/apt/archives/gcc-4.7-base_4.7.2-0ubuntu3_amd64.deb

drwxr-xr-x root/root         0 2012-11-15 12:56 ./

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/lib/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/lib/gcc/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/lib/gcc/x86_64-linux-gnu/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/lib/gcc/x86_64-linux-gnu/4.7/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/share/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/share/doc/

drwxr-xr-x root/root         0 2012-11-15 12:56 ./usr/share/doc/gcc-4.7-base/

-rw-r--r-- root/root      1716 2012-11-15 12:35 ./usr/share/doc/gcc-4.7-base/TODO.Debian

-rw-r--r-- root/root      2365 2012-11-15 12:56 ./usr/share/doc/gcc-4.7-base
/changelog.Debian.gz
-rw-r--r-- root/root      3357 2012-11-15 12:35 ./usr/share/doc/gcc-4.7-base/README.Debian.amd64.gz

-rw-r--r-- root/root     25568 2012-11-15 12:55 ./usr/share/doc/gcc-4.7-base/copyright


lrwxrwxrwx root/root         0 2012-11-15 12:56 ./usr/lib/gcc/x86_64-linux-gnu/4.7.2 -> 4.7
share|improve this answer
1  
Hi. It would be nice if you could edit, your answer and clarify what you're trying to convey. For now this looks like something that should have been a comment, rather than an answer to the OP's question. –  saji89 Oct 26 '13 at 8:51
add comment

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.