删除软件包 lazarus-src-2.2 时出错:dpkg-divert:错误:文件名“to”不是绝对路径

删除软件包 lazarus-src-2.2 时出错:dpkg-divert:错误:文件名“to”不是绝对路径

我正在尝试从我的 Ubuntu 系统上删除“lazarus-src-2.2”包,但遇到了无法解决的错误。以下是sudo apt remove lazarus-src-2.2命令:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  lazarus-src-2.2
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
1 not fully installed or removed.
After this operation, 158 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... currently installed 586632 files and directories.)
Removing lazarus-src-2.2 (2.2.0+dfsg1-5ubuntu1) ...
dpkg-divert: error: file name 'to' is not an absolute path

Use --help for help about diverting files.
dpkg: error processing package lazarus-src-2.2 (--remove):
 installed lazarus-src-2.2 package post-removal script returned error exit status 2
Too many errors encountered, stopping
Processing triggers for libc-bin (2.31-0ubuntu9.16) ...
Errors were encountered while processing:
 lazarus-src-2.2
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

我该如何解决这个问题并成功删除“lazarus-src-2.2”包?我尝试重新安装该包并使用 dpkg --remove --force-remove-reinstreq 命令,但没有成功。任何帮助都将不胜感激!

sudo apt list | grep "lazarus"

lazarus-2.2/jammy,jammy 2.2.0+dfsg1-5ubuntu1 all
lazarus-doc-2.2/jammy,jammy,now 2.2.0+dfsg1-5ubuntu1 all [installed]
lazarus-doc/jammy,jammy,jammy 2.2.0+dfsg1-5ubuntu1 all
lazarus-ide-2.2/jammy,jammy,now 2.2.0+dfsg1-5ubuntu1 amd64 [installed]
lazarus-ide-gtk2-2.2/jammy,now 2.2.0+dfsg1-5ubuntu1 amd64 [installed]
lazarus-ide-gtk2/jammy,jammy 2.2.0+dfsg1-5ubuntu1 all
lazarus-ide-qt5-2.2/jammy 2.2.0+dfsg1-5ubuntu1 amd64
lazarus-ide-qt5/jammy,jammy 2.2.0+dfsg1-5ubuntu1 all
lazarus-ide/jammy,jammy,now 2.2.0+dfsg1-5ubuntu1 all [installed]
lazarus-src-2.2/jammy,jammy,now 2.2.0+dfsg1-5ubuntu1 all [installed]
lazarus-src/jammy,jammy,jammy 2.2.0+dfsg1-5ubuntu1 all
lazarus/jammy,jammy 2.2.0+dfsg1-5ubuntu1 all 

uname -a

Linux user-pc 5.15.0-73-generic #80-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

答案1

于是,我花了几天时间解决了这个问题。你需要删除与

sudo dpkg-divert --remove PATH

我把修复此错误所需的一切都放入了 1 个 bash 脚本中。

#!/bin/bash

# Get a list of diversions with paths
diversions=$(dpkg-divert --list 'lazarus*')

# Split the output into strings
IFS=$'\n'

# Passing through each line of output
For line in $diversions; do
  # Extract the path from the line
  path=$(echo $line | awk '{print $2}')

  # Execute the command with the path substituted
  sudo dpkg-divert --remove --no-rename "$path"

#Remove the rest of the garbage
sudo apt-get install -f
sudo apt autoremove

done

PS 你可以替换包名称‘拉撒路’(第 4 行)与您的任何包裹一起

相关内容