所以我尝试设置我的电脑以进行开发。我安装了 ubuntu 14.04 LTS。我想写一个 hello-world 程序。但是我无法编译它。经过一番搜索,我尝试了sudo apt-get install build-essential
,结果显示:
>sudo apt-get install build-essential
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:
build-essential : Depends: g++ (>= 4:4.4.3) but it is not going to be installed
Depends: dpkg-dev (>= 1.13.5) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
我尝试更改源和sudo apt-get update
,sudo apt-get upgrade
但问题仍然存在。我尝试了sudo apt-get autoclean
,sudo apt-get install --fix-broken
或类似的方法,但都不起作用。
另外,我尝试过sudo aptitude why-not build-essential
,它说:
>sudo aptitude why-not build-essential
p gvfs-bin:i386 Provides gvfs-bin
p gvfs-bin:i386 Suggests gvfs:i386
p gvfs:i386 Suggests gvfs-backends:i386
p gvfs-backends:i386 Depends libgphoto2-port10:i386 (>= 2.5.2)
p libgphoto2-port10:i386 Suggests gphoto2:i386 (> 2.1.0)
p gphoto2:i386 Suggests gthumb:i386
p gthumb:i386 Recommends flex:i386
p flex:i386 Suggests build-essential:i386
p build-essential:i386 Conflicts build-essential
那么这里到底出了什么问题?
还有我的sources.list
文件:
>cat /etc/apt/sources.list
# deb cdrom:[Ubuntu 14.04.4 LTS _Trusty Tahr_ - Release amd64 (20160217.1)]/ trusty main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.163.com/ubuntu/ trusty main restricted
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted
## Major bug fix updates produced after the final release of the
## distribution.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.163.com/ubuntu/ trusty universe
deb-src http://mirrors.163.com/ubuntu/ trusty universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.163.com/ubuntu/ trusty multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner
## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://extras.ubuntu.com/ubuntu trusty main
deb-src http://extras.ubuntu.com/ubuntu trusty main
我的sources.list.d
目录:
>ls -la /etc/apt/sources.list.d
total 8
drwxr-xr-x 2 root root 4096 4月 10 2014 .
drwxr-xr-x 6 root root 4096 4月 14 14:16 ..
顺便问一下,有人能简单解释一下什么是损坏的软件包以及为什么它这么容易出现吗?或者发生这种情况的可能原因是什么?apt-get 难道不应该能够修复此类问题或至少在这里提供一些有用的信息吗?我最近多次遇到此错误,但找不到任何解决方案。
多谢。
答案1
经过一段时间的努力,我找到了解决这个问题的方法。
首先sudo apt-get install aptitude
,它工作正常。然后尝试sudo aptitude install build-essential
,它首先指出存在问题并提出解决方案。它提出的第一个解决方案不保留任何变化,这不是我们想要的,因此选择no
。它提出了第二个解决方案,它可以工作。
顺便说一句,我仍然感到困惑,为什么我在新安装的 ubuntu 系统上会“保留损坏的软件包”?“保留损坏的软件包”是什么意思?
答案2
由于某种原因,您安装了build-essential:i386
(32
位版本),并且您的系统就像您说的,它是64
位(即amd64
)。
首先,删除build-essential:i386
:
sudo apt-get remove build-essential:i386
然后安装64位版本:
sudo apt-get install build-essential