无法安装 gcc 和 g++

无法安装 gcc 和 g++

我拥有以我的..rm-r开头的所有文件。gccg++/usr/bin

现在,当我尝试使用重新安装它时,sudo apt-get install gcc出现以下错误

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)  

我尝试了以下命令:

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

结果如下:

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.

答案1

尝试重新安装:

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

答案2

如果你安装了 synaptic,也许你会进步得更快。你会更好地了解自己的情况。

我猜你安装了一些不兼容的库,它们被“卡住了”。g++ 或 gcc 依赖它们,但版本控制中的一些奇怪之处阻止了 apt-get 更新这些部分。也许它们是从第三方存储库安装的?

@Benny 的回答中建议强制删除 gcc 和 g++,这可能是一个好的方向,但由于 g++ 被一些未知的第三个库阻止安装,因此它无法帮助您一路回家。根据您遇到的情况,您可能最终会删除几层。

在使用synaptic弄清楚发生了什么之后,我会切换到终端并使用dpkg来删除软件包,而不是apt-get,因为我会在删除东西时避免与互联网软件包服务器产生任何纠缠。您通常不必担心删除东西,因为 apt-get 会放回依赖项。但是,如果您不小心,那么删除一个软件包可能会不必要地触发 100 个软件包的删除。阅读man dpkg,我预计“--no-force-depends”可能会有所帮助。如果可以,请避免使用 --force,但“--ignore-depends=?pkg_name”可能会有所帮助。我会先在试运行模式下尝试此操作以诊断问题。

相关内容