我收到以下错误:
root@56709:/etc/nginx/conf.d# apt install php7.4-dev
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:
php7.4-dev : Depends: libpcre2-dev (>= 10.30) but it is not going to be installed
Depends: libssl-dev but it is not going to be installed
Depends: php7.4-common (= 7.4.3-4ubuntu2.4) but 7.4.11-6+ubuntu16.04.1+deb.sury.org+1 is to be installed
Recommends: pkg-php-tools but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
运行时apt install php7.4-dev
有什么想法如何修复它吗?
我尝试使用 aptitude 而不是 apt,结果如下
root@56709:/etc/nginx/conf.d# sudo aptitude install php7.4-dev
The following NEW packages will be installed:
libpcre2-16-0{a} libpcre2-32-0{a} libpcre2-dev{ab} libpcre2-posix2{a} libssl-dev{ab} php7.4-dev{b} pkg-php-tools{a} shtool{a}
0 packages upgraded, 8 newly installed, 0 to remove and 2 not upgraded.
Need to get 3,295 kB of archives. After unpacking 17.7 MB will be used.
The following packages have unmet dependencies:
php7.4-dev : Depends: php7.4-common (= 7.4.3-4ubuntu2.4) but 7.4.11-6+ubuntu16.04.1+deb.sury.org+1 is installed
libpcre2-dev : Depends: libpcre2-8-0 (= 10.34-7) but 10.35-5+ubuntu16.04.1+deb.sury.org+1 is installed
libssl-dev : Depends: libssl1.1 (= 1.1.1f-1ubuntu2) but 1.1.1g-1+ubuntu16.04.1+deb.sury.org+1 is installed
The following actions will resolve these dependencies:
Keep the following packages at their current version:
1) libpcre2-dev [Not Installed]
2) libssl-dev [Not Installed]
3) php7.4-dev [Not Installed]
我目前使用的是 ubuntu 20.0.4,但如果我看到上面的内容,我认为我仍然指的是 16.04..需要以某种方式更新源吗?
答案1
@Henning Kockerbeck 的解释很棒。以下是两行解决方案这篇博文
复制粘贴代码以避免将来出现链接腐烂:
# apt install libssl-dev
The following packages have unmet dependencies:
libssl-dev : Depends: libssl1.1 (= 1.1.1-1ubuntu2.1~18.04.9) but 1.1.1d-1+ubuntu18.04.1+deb.sury.org+2 is to be installed
E: Unable to correct problems, you have held broken packages.
这解释了存在冲突的各种版本,由于这些冲突,您可能必须将包“保留”到看起来apt
不是最新版本的特定版本:
# apt-cache policy libssl1.1
libssl1.1:
Installed: 1.1.1g-1+ubuntu18.04.1+deb.sury.org+1
Candidate: 1.1.1g-1+ubuntu18.04.1+deb.sury.org+1
Version table:
*** 1.1.1g-1+ubuntu18.04.1+deb.sury.org+1 100
100 /var/lib/dpkg/status
1.1.1-1ubuntu2.1~18.04.9 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
1.1.0g-2ubuntu4 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
这将安装特定版本。请记住,这是一个定时炸弹,当您稍后想要升级时,您必须删除此版本的软件包/取消保留它。
# apt install libssl1.1=1.1.1-1ubuntu2.1~18.04.9
现在版本正确,php7.x-dev 将正确安装
# apt-cache policy libssl1.1
libssl1.1:
Installed: 1.1.1-1ubuntu2.1~18.04.9
Candidate: 1.1.1-1ubuntu2.1~18.04.9
Version table:
*** 1.1.1-1ubuntu2.1~18.04.9 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
100 /var/lib/dpkg/status
1.1.0g-2ubuntu4 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
上面的次要版本可能会有所不同,但想法是一样的 - Sury 的软件包导致系统的 libssl 软件包出现问题。肯定还有其他解决方案可以继续使用 Sury 版本的 libssl,毕竟他已经维护这些软件包十年了,这意味着他一定知道自己在做什么,但我不知道这种替代方法的细节。
答案2
看起来好像你安装了来自 PPA 的旧软件包,导致一切陷入混乱。
您尝试安装php7.4-dev
。该包依赖php7.4-common
对于 Ubuntu 20.04 来说,实际上php7.4-common
是7.4.3-4ubuntu2.4
。
但是您已经php7.4-common
安装了一个软件包,即7.4.11-6+ubuntu16.04.1+deb.sury.org+1
。这似乎是大约八个 Ubuntu 版本之前的软件包,但 PHP 版本略新(7.4.11 对比 7.4.3)。所以apt
更喜欢据说较新的软件包。但是7.4.11-6+ubuntu16.04.1+deb.sury.org+1
来自 PPA 的 不适用于php7.4-dev
来自 Ubuntu 20.04s 存储库的 。所以apt
它举手投降并放弃了。
如果你不再需要它,你应该删除 PPA 和从中安装的所有软件包。也许有额外的 PPA 或软件包会造成混乱,但无论如何,上述情况似乎都是一个问题。
答案3
aptitude
输出表明无法满足依赖关系,因为已经安装了来自第三方存储库的冲突包:
libpcre2-dev:依赖:libpcre2-8-0(= 10.34-7)但已安装 10.35-5+ubuntu16.04.1+deb.sury.org+1
deb.sury.org
您的软件包源(/etc/apt/sources.list
和子目录)中是否存在相关内容?
你试过了吗apt autoremove
?这将删除未安装软件包的依赖项(即,任何已安装软件包都不需要的自动安装软件包)。
答案4
我在安装 PHP 8.0 时收到了类似的错误,我安装了中提到的所有依赖项Depends:
并解决了问题。