0

I have rm-r all the files starting with gcc and g++ from my /usr/bin..

Now when I am trying to reinstall it using sudo apt-get install gcc I am getting following error

Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version (4:5.3.1-1ubuntu1).
The following packages were automatically installed and are no longer required:
  libgcrypt20:i386 libsystemd0:i386 linux-headers-4.4.0-38 linux-headers-4.4.0-38-generic
  linux-image-4.4.0-38-generic linux-image-extra-4.4.0-38-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up gcc (4:5.3.1-1ubuntu1) ...
update-alternatives: error: alternative path /usr/bin/gcc doesn't exist
dpkg: error processing package gcc (--configure):
 subprocess installed post-installation script returned error exit status 2
Errors were encountered while processing:
 gcc
E: Sub-process /usr/bin/dpkg returned an error code (1)  

I tried the following commands:

sudo dpkg --purge --force-depends gcc 
sudo apt-get autoremove -y
sudo apt-get autoclean -y
sudo apt-get clean gcc  

These were the results:

Some packages could not be installed. 
This may mean that you have requested an impossible situation   
or if you are using the unstable distribution that some required packages   
have not yet been created or been moved out of Incoming.   
The following information may help to resolve the situation:   
The following packages have unmet dependencies: 
 build-essential : Depends: g++ (>= 4:5.2) but it is not going to be installed 
E: Unable to correct problems, you have held broken packages.
karel
  • 114,770

2 Answers2

0

Maybe you'll make progress faster if you install synaptic. You'll get a nicer view of your situation.

I guess you have some incompatible libraries installed and those are "wedged". g++ or gcc depend on them, but something funny in your versioning prevents apt-get from updating those pieces. Perhaps they were installed from a third party repository?

Suggestion in @Benny's answer to force remove gcc and g++ might be step in good direction, but since g++ is blocked from installation by some unknown third library, it does not help you to get all the way home. Depending on how you got in this situation, you may end up removing several layers.

After using synaptic to figure out what is going on, I'd change to terminal and use dpkg to remove the packages, not apt-get, because I'd avoid any entanglement with internet package servers while stripping things away. You don't generally have to worry about removing things because apt-get will put back the dependencies. However, if you are not careful, then removing one package might trigger the removal of 100s unnecessarily. Read man dpkg, I expect "--no-force-depends" may help. Avoid --force if you can, but "--ignore-depends=?pkg_name" may help. I'd try this in dry-run mode first to diagnose the problem.

pauljohn32
  • 3,743
  • Also could try clicking the Edit -> Fix Broken Packages option in Synaptic. Sometimes it fixes some of the broken packages the first time that it is clicked and if you click it again it fixes additional broken packages the second time that it is clicked. – karel Oct 30 '18 at 02:33
0

Try to reinstall:

sudo dpkg --purge --force-depends gcc 
sudo apt-get autoremove -y
sudo apt-get autoclean -y
sudo apt-get clean gcc
sudo apt-get install gcc
Benny
  • 4,920
  • Hey thanks for reply!! I have applied all 3 steps mentioned above...Got new error as below... – Henil Naik Oct 23 '16 at 07:46
  • Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

    The following packages have unmet dependencies: build-essential : Depends: g++ (>= 4:5.2) but it is not going to be installed E: Unable to correct problems, you have held broken packages.

    – Henil Naik Oct 23 '16 at 07:47