ubuntu apt报depends xxx but it is not installed问题解决

问题现象:

执行apt时,报Depends: xxx but it is not installed,根据提示运行sudo apt –fix-broken install也无法解决:

$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 nvidia-compute-utils-535 : Depends: libnvidia-compute-535 but it is not installed
 libnvidia-decode-535 : Depends: libnvidia-compute-535 (= 535.183.01-0ubuntu0.20.04.1) but it is not installed
 nvidia-driver-535 : Depends: libnvidia-gl-535 (= 535.183.01-0ubuntu0.20.04.1) but it is not installed
                     Depends: libnvidia-compute-535 (= 535.183.01-0ubuntu0.20.04.1) but it is not installed
                     Depends: libnvidia-extra-535 (= 535.183.01-0ubuntu0.20.04.1) but it is not installed
                     Depends: nvidia-utils-535 (= 535.183.01-0ubuntu0.20.04.1) but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

解决方法:

# 1. 查找损坏的包
$ sudo dpkg --configure -a
dpkg: dependency problems prevent configuration of nvidia-compute-utils-535:
 nvidia-compute-utils-535 depends on libnvidia-compute-535; however:
  Package libnvidia-compute-535:arm64 is not installed.
dpkg: error processing package nvidia-compute-utils-535 (--configure):


# 2. 尝试强制删除损坏包,提示无法删除,有依赖的包,顺藤摸瓜找到损坏包依赖链条
$ sudo dpkg -r nvidia-compute-utils-535
dpkg: dependency problems prevent removal of nvidia-compute-utils-535:
 nvidia-driver-535 depends on nvidia-compute-utils-535 (= 535.183.01-0ubuntu0.20.04.1); however:
  Package nvidia-compute-utils-535 is to be removed.

$ sudo dpkg -r nvidia-driver-535 
dpkg: dependency problems prevent removal of nvidia-driver-535:
 nvidia-driver-525 depends on nvidia-driver-535.


# 3. 根据依赖链条反向递归清理损坏包
$ sudo dpkg -r nvidia-driver-525
(Reading database ... 269091 files and directories currently installed.)
Removing nvidia-driver-525 (525.147.05-0ubuntu2.20.04.1) ...

$ sudo dpkg -r nvidia-driver-535 
(Reading database ... 269088 files and directories currently installed.)
Removing nvidia-driver-535 (535.183.01-0ubuntu0.20.04.1) ...

$ sudo dpkg -r nvidia-compute-utils-535
(Reading database ... 269018 files and directories currently installed.)
Removing nvidia-compute-utils-535 (535.183.01-0ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...

# 4. 检查apt是否恢复正常
$ sudo apt install -y curl

 

欢迎关注下方“非著名资深码农“公众号进行交流~

发表评论

邮箱地址不会被公开。