安装 Apache2 时出错

安装 Apache2 时出错

安装 Apache2 时我收到以下输出:

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:
 apache2 : Depends: apache2-bin (= 2.4.7-1ubuntu4.4) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

apt-cache policy apache2 apache2-bin 的输出

apache2:
  Installed: (none)
  Candidate: 2.4.7-1ubuntu4.4
  Version table:
     2.4.7-1ubuntu4.4 0
        500 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
apache2-bin:
  Installed: (none)
  Candidate: 2.4.7-1ubuntu4.4
  Version table:
     2.4.7-1ubuntu4.4 0
        500 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages

我怎样才能解决这个问题?

我已经尝试了你建议的命令。apt-get upgrade -f 的输出

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  linux-generic-lts-utopic linux-headers-generic-lts-utopic
  linux-image-generic-lts-utopic
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

此命令无输出dpkg --get-selections | grep -i ^apache2

代码输出:apt-mark 取消保留 apache2-bin

apache2-bin was already not hold.

代码输出:apt-cache 依赖于 apache2-bin

apache2-bin
  Depends: <libapr1>
  Depends: <libaprutil1>
 |Depends: <libaprutil1-dbd-sqlite3>
 |Depends: <libaprutil1-dbd-mysql>
 |Depends: <libaprutil1-dbd-odbc>
 |Depends: <libaprutil1-dbd-pgsql>
  Depends: <libaprutil1-dbd-freetds>
  Depends: <libaprutil1-ldap>
  Depends: libc6
  Depends: libldap-2.4-2
  Depends: libpcre3
  Depends: libssl1.0.0
  Depends: libxml2
  Depends: zlib1g
  Depends: perl
  Suggests: <www-browser>
    chromium-browser
    firefox
    konqueror
  Suggests: apache2-doc
 |Suggests: apache2-suexec-pristine
  Suggests: apache2-suexec-custom
  Conflicts: apache2.2-bin
  Conflicts: apache2.2-bin:i386
  Conflicts: <apache2.2-common>
  Conflicts: <apache2.2-common:i386>
  Breaks: libapache2-mod-macro
  Breaks: libapache2-mod-macro:i386
  Breaks: libapache2-mod-proxy-html
  Breaks: libapache2-mod-proxy-html:i386
  Replaces: apache2-mpm-event
  Replaces: apache2-mpm-event:i386
  Replaces: apache2-mpm-itk
  Replaces: apache2-mpm-itk:i386
  Replaces: apache2-mpm-prefork
  Replaces: apache2-mpm-prefork:i386
  Replaces: apache2-mpm-worker
  Replaces: apache2-mpm-worker:i386
  Replaces: apache2.2-bin
  Replaces: apache2.2-bin:i386
  Replaces: <apache2.2-common>
  Replaces: <apache2.2-common:i386>
  Replaces: libapache2-mod-macro
  Replaces: libapache2-mod-macro:i386
  Replaces: libapache2-mod-proxy-html
  Replaces: libapache2-mod-proxy-html:i386
  Conflicts: apache2-bin:i386

但问题尚未解决。

答案1

您可能知道,您可以将软件包固定到其当前版本。这是通过将软件包的状态设置为“保留”来实现的。例如,如果您安装了某个软件包的 1.1 版本并将该软件包的状态设置为“保留”,则即使 1.2 或更高版本可用,它也不会更新。

在您的情况下,似乎有一个或多个软件包被设置为“保留”。这会禁止 apt-get 在您尝试安装时解决某些依赖关系apache2。例如,您固定apache2-bin在早于 2.4.7-1ubuntu4.4 的版本。然后您尝试apache2在版本 2.4.7-1ubuntu4.4 中安装。apache2 2.4.7-1ubuntu4.4依赖于apache2-bin 2.4.7-1ubuntu4.4,因此 apt-get 也会尝试通过安装来解决此依赖关系apache2-bin 2.4.7-1ubuntu4.4。但它无法这样做,因为apache2-bin的状态为“保留”以前的版本。因此,apt-get 会告诉您“无法纠正问题,您保留了损坏的软件包。”

这只是可能出现的情况之一,但它应该能让您了解问题可能出在哪里。

你可以尝试两种方法:一种是使用 apt-get 来尝试解决问题。这应该可以让你一些解决方案,但不一定是你要找的解决方案。让 apt-get 尝试修复混乱的命令是

apt-get upgrade -f

意思-f是“修复损坏的”,或者更确切地说是“尝试修复损坏的东西”。

另一种可能性是自己查找固定的软件包并“取消固定”。这需要做更多的工作,但与告诉 apt-get“只需执行”相比,我更喜欢这样做某物使之正确” ;)

您可以使用以下命令获取所有已安装软件包的状态

dpkg --get-selections

要过滤感兴趣的内容,你可以直接 grep 名字,比如说

dpkg --get-selections | grep -i ^apache2

那应该会给你类似

apache2                     install
apache2-bin                 install
apache2-data                install
apache2-doc                 install

我假设与 Apache 相关的一个或多个软件包处于“暂停”状态。您可以通过以下方式更改软件包的状态:

# set a package to status "hold"
apt-mark hold somepackage
# for example
apt-mark hold apache2-bin

# remove status "hold" from a package
apt-mark unhold somepackage
# for example
apt-mark unhold apache2-bin

“阻碍”的包可能是apache2-bin它本身,也可能是另一个apache2-bin依赖它的包。你可以检查一个包依赖哪些包,方法是

apt-cache depends somepackage

例如

apt-cache depends apache2-bin

相关内容