11

I recently tried to downgrade to gcc 4.7 since a cfd code I was working on didn't compile with the latest gcc version. But after many errors and the code still not compiling I gave up and would like to go back to the latest gcc and g++ compilers however it seems I may have messed something up.

When I do:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
sudo apt-get install gcc-6.2 g++-6.2

or even gcc-5.1 g++-5.1 for that matter, it gives me the following error

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package gcc-6.2
E: Couldn't find any package by glob 'gcc-6.2'
E: Couldn't find any package by regex 'gcc-6.2'
E: Unable to locate package g++-6.2
E: Couldn't find any package by glob 'g++-6.2'
E: Couldn't find any package by regex 'g++-6.2'

and I also tried doing this before

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6.2 g++-6.2

but it doesn't seem to work. Finally when I just do

sudo apt-get install gcc

it says

Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version (4:5.3.1-1ubuntu1).

I know I still need to install and configure alternatives but doing that doesn't work either as follows

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5.3 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Sorry this ended up quite long and please let me know if you need more info. Thanks!

EDIT: I actually got it to work by changing gcc-5.3 to gcc-5 in the above code as that seemed to be what it's called in usr/bin. I will keep it for future reference if anyone faces the same problem.

  • 2
    AFAIK gcc and g++ don't install as update-alternatives by default - instead, the gcc and g++ dependency packages install direct links to the default dependencies, like /usr/bin/g++ -> g++-5. Have you tried simply reinstalling the gcc and g++ packages? – steeldriver Aug 22 '16 at 11:49
  • One way of avoiding this type of issues is to create a VM and install the old compiler version in there. – NZD Aug 23 '16 at 7:29
  • This hotfix can be fixed in the installation Reading package lists... Done Building dependency tree Reading state information... Done gcc is already the newest version (4:7.3.0-3ubuntu2.1). 0 upgraded, 0 newly installed, 0 to remove and 36 not upgraded. – JOC KERS Mar 12 at 20:06
5

Run the following commands in sequence. I was getting same error. This worked for me.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-snapshot
sudo apt-get install gcc-6 g++-6
  • 9
    Why does sudo apt-get update have be run three times instead of just the first time? In particular, why after the last package installation? – Eliah Kagan Jan 28 '17 at 3:07
  • What does the gcc-snapshot exactly do? How can I remove the previous gcc version (4.8.4) ? – abunickabhi Sep 4 at 16:04

protected by Community Mar 12 at 22:53

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

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.