Score:1

Error while removing package lazarus-src-2.2: dpkg-divert: error: file name 'to' is not an absolute path

gp flag
Jim

I'm trying to remove the "lazarus-src-2.2" package on my Ubuntu system, but I'm encountering an error that I can't resolve. Here's the output of the sudo apt remove lazarus-src-2.2 command:

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)

How can I solve this issue and successfully remove the "lazarus-src-2.2" package? I've tried reinstalling the package and using the dpkg --remove --force-remove-reinstreq command, but with no success. Any help would be appreciated!

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

hr flag
It might be helpful to [edit] your question to include the output of `dpkg-divert --list` or at least `dpkg-divert --list 'lazarus*'`
Jim avatar
gp flag
Jim
@steeldriver thanks! I added a reply, with your command
Score:0
gp flag
Jim

And so, I solved this problem after a few days. You need to delete the conflicting files with the

sudo dpkg-divert --remove PATH

Everything you might need to fix this error I put into 1 bash script.

#!/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

P.S. you can replace the package name 'lazarus' (line: 4) with any of your packages

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.