ubuntu使用apt安装包提示 g++ : Depends: g++-5 (>= 5.3.1-3~) but it is not going to be installed 缺少依赖包

本文解决了一个在Windows子系统下的Ubuntu 20.04环境中安装G++和GDB时遇到的依赖错误问题。通过更换为适配版本的镜像源并更新软件包缓存及已安装的软件包后,成功安装了所需的编译器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我用的windows子系统下的ubuntu,20.04版本,在设置了清华的如下镜像之后,安装g++和gdb总是报错

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe

安装g++如下

sudo apt-get install -y g++
The following packages have unmet dependencies:
 g++ : Depends: g++-5 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

然后我再安装g++ -5还是说缺少依赖包,这样一直下去不就形成了一个死局了嘛?
于是我想那可能不是依赖的问题了,是不是源对应的ubuntu版本的问题?因为我安装软件的时候发现了16.xx这类版本的信息,和我这个版本对不上。

于是我上网搜索到了20.04版本的源,链接在这儿
我选的清华的源

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

接着先更新下可安装包的缓存,sudo apt update,在更新下安装的包,sudo apt upgrade
接着安装g++和gdb,成功了。

sudo apt-get install kdevelop后出现Reading package lists... Done Building dependency tree Reading state information... Done 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: kdevelop : Depends: kdevelop57-libs (= 4:21.12.3-0ubuntu1) but it is not going to be installed Depends: kinit but it is not going to be installed Depends: kio but it is not going to be installed Depends: libkasten4controllers0 (>= 5:0.26.2) but it is not going to be installed Depends: libkasten4core0 (>= 5:0.26.2~) but it is not going to be installed Depends: libkasten4okteta2controllers0 (>= 5:0.26.2) but it is not going to be installed Depends: libkasten4okteta2core0 (>= 5:0.26.2~) but it is not going to be installed Depends: libkasten4okteta2gui0 (>= 5:0.26.2~) but it is not going to be installed Depends: libkf5bookmarks5 (>= 5.69.0) but it is not going to be installed Depends: libkf5configwidgets5 (>= 4.96.0) but it is not going to be installed Depends: libkf5declarative5 (>= 5.45.0) but it is not going to be installed Depends: libkf5iconthemes5 (>= 5.50.0~) but it is not going to be installed Depends: libkf5kiocore5 (>= 5.50.0~) but it is not going to be installed Depends: libkf5kiofilewidgets5 (>= 5.50.0~) but it is not going to be installed Depends: libkf5kiogui5 (>= 5.69.0) but it is not going to be installed Depends: libkf5kiowidgets5 (>= 5.70.0) but it is not going to be installed Depends: libkf5newstuff5 (>= 5.50.0~) but it is not going to be installed Depends: libkf5parts5 (>= 5.50.0~) but it is not going to be installed Depends: libkf5purpose-bin but it is not going to be installed Depends: libkf5purpose5 (>= 5.44.0) but it is not going to be installed Depends: libkf5texteditor5 (>= 5.50.0) but it is not going to be installed Depends: libkf5textwidgets5 (>= 4.96.0) but it is not going to be installed Depends: libkf5xmlgui5 (>= 5.50.0~) but it is not going to be installed Depends: libkomparediff2-5 (>= 4:21.12.3~) but it is not going to be installed Depends: libokteta3gui0 (>= 5:0.26.2~) but it is not going to be installed Depends: libprocesscore9 (>= 4:5.18.90) but it is not going to be installed Depends: libprocessui9 (>= 4:5.18.90) but it is not going to be installed Recommends: kapptemplate but it is not going to be installed Recommends: kio-extras but it is not going to be installed ros-noetic-executive-smach : Depends: ros-noetic-smach-ros but it is not going to be installed ros-noetic-rosservice : Depends: ros-noetic-rosmsg but it is not going to be installed ros-noetic-roswtf : Depends: ros-noetic-rosnode but it is not going to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
最新发布
07-25
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值