Nginx 未满足依赖关系,无法升级/删除

Nginx 未满足依赖关系,无法升级/删除

最近我在我的 Ubuntu 服务器上安装了 newrelic,之后我开始在日志中自动收到无法加载 newrelic 扩展的错误。

我尝试升级/删除 newrelic 但在两种情况下都出现错误:

ubuntu@ip:/etc/php$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 nginx : Depends: nginx-core (< 1.10.0-0ubuntu0.16.04.4.1~) but 1.10.3-0ubuntu0.16.04.1 is installed or
                  nginx-full (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not installed or
                  nginx-light (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not installed or
                  nginx-extras (< 1.10.0-0ubuntu0.16.04.4.1~) but it is not installed
E: Unmet dependencies. Try using -f.

我尝试运行sudo apt-get -f install但结果输出:

ubuntu@ip:/etc/php$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-78 linux-headers-4.4.0-78-generic linux-headers-4.4.0-79 linux-headers-4.4.0-79-generic
  linux-image-4.4.0-78-generic linux-image-4.4.0-79-generic nginx-common nginx-core
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  nginx
The following packages will be upgraded:
  nginx
1 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
7 not fully installed or removed.
Need to get 787 kB of archives.
After this operation, 2,777 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
  nginx
Install these packages without verification? [y/N] y
Get:1 http://nginx.org/packages/ubuntu xenial/nginx amd64 nginx amd64 1.12.1-1~xenial [787 kB]
Fetched 787 kB in 2s (275 kB/s)
(Reading database ... 138963 files and directories currently installed.)
Preparing to unpack .../nginx_1.12.1-1~xenial_amd64.deb ...
Unpacking nginx (1.12.1-1~xenial) over (1.10.0-0ubuntu0.16.04.4) ...
dpkg: error processing archive /var/cache/apt/archives/nginx_1.12.1-1~xenial_amd64.deb (--unpack):
 trying to overwrite '/etc/nginx/uwsgi_params', which is also in package nginx-common 1.10.3-0ubuntu0.16.04.1
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/nginx_1.12.1-1~xenial_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我确实找到了一篇文章建议删除 nginx 然后重新安装。这是一台具有持续流量的生产服务器,因此我想避免卸载 nginx 之后出现故障的风险。我更改了 nginx 的配置,但没有记录所有更改。有什么安全的方法可以解决这个问题吗?

答案1

经过研究和试验了很多东西后,我找不到任何解决方案,最后遵循了这个https://askubuntu.com/questions/243568/nginx-dependency-problem-trying-to-upgrade

我做了以下事情:

  1. 我备份了/etc/nginx
  2. 然后删除 nginx
  3. 重新安装 nginx
  4. 然后,当它被/etc/nginx备份文件夹替换时,它开始工作

我做这些事大概花了 15 到 20 分钟的时间。

答案2

可以通过将 force-overwrite 传递给底层 dpkg 进程来解决此问题。这是我使用的命令:

sudo apt -o Dpkg::Options::="--force-overwrite" upgrade nginx

来源:https://askubuntu.com/questions/56761/force-apt-get-to-overwrite-file-installed-by-another-package

答案3

  1. 先跑吧apt list --upgradable

  2. 下一次运行sudo apt-get install <package-name>从列表顶部的包开始。

  3. 再次运行apt list --upgradable以检查所有软件包是否已安装。 如果没有,请重复步骤 1 和 2。

相关内容