The "dpkg-divert: error: rename involves overwriting" error occurs when dpkg-divert tries to rename a file during package operations but finds a different file in the target location. This typically happens due to package conflicts, leftover files from failed installations, or incorrect diversion configurations.
dpkg-divert is a utility used to temporarily override Debian package files when there are conflicts between packages. When adding or removing a diversion with the --rename option, dpkg-divert attempts to physically move the file to its diverted location (or restore it). This error occurs when the destination path already contains a different file than what dpkg-divert expects. This can happen when: - Multiple packages try to manage the same file - Previous package installations left orphaned files - Manual edits corrupted the diversions database at /var/lib/dpkg/diversions - A file that was supposed to be managed by a diversion was overwritten by another package The error prevents the file operation from completing because dpkg-divert cannot safely overwrite an unexpected file without potentially losing data.
First, examine what diversions exist on your system:
dpkg-divert --listThis will show all active diversions and help identify which file is causing the conflict. Look for the file mentioned in your error message.
Look for orphaned files in common diversion directories:
ls -la /usr/lib/mesa-diversions/
ls -la /usr/lib/nvidia/diversions/
ls -la /etc/alternatives/If you find files that don't correspond to active diversions (from dpkg-divert --list), these may be causing conflicts. Note their full paths.
If you identified the conflicting file, try to remove the diversion:
dpkg-divert --remove /path/to/conflicting/fileIf this works, the issue is resolved. If it still fails with the same error, proceed to the next step.
If dpkg-divert --remove fails, you can manually remove the blocking file:
sudo mv /usr/lib/xorg/modules/extensions/libglx.so /usr/lib/xorg/modules/extensions/libglx.so.backupReplace the path with your actual conflicting file. Use mv instead of rm to keep a backup in case you need to restore it.
After moving the file, retry the package operation:
sudo apt update && sudo apt install -fIf manual removal doesn't resolve the issue, completely remove and reinstall the conflicting packages:
# First, identify which package owns the conflicting file
dpkg -S /path/to/conflicting/file
# Purge the conflicting package (removes all files including diversions)
sudo apt purge package-name
# Verify all diversions for that package are gone
dpkg-divert --list | grep package-name
# Reinstall the package cleanly
sudo apt install package-nameThis forces dpkg to reset the diversion state and properly configure the package.
Understanding Diversion Mechanics:
- dpkg-divert works by maintaining a database in /var/lib/dpkg/diversions that tells dpkg where to install files
- The --rename option causes the original file to be physically renamed to a diverted location
- Without --no-rename, the file must be moved atomically; if the target exists, the operation fails
- Package maintainer scripts use dpkg-divert in preinst/prerm hooks to manage file conflicts
Common Scenarios by Technology:
- Mesa/GLX conflicts: libgl1-mesa-swx11 and mesa-diversions competing for libglx.so
- X.org extensions: Multiple X11 packages managing /usr/lib/xorg/modules/extensions/
- Dictionary packages: dictionaries-common managing shared dictionary files
Prevention Tips:
- Do not manually edit /var/lib/dpkg/diversions (it's not a text config file)
- Avoid mixing conflicting packages with incompatible diversion schemes
- When removing packages, use apt purge rather than just apt remove to clean up diversions
- Check for pending diversions before major package updates
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt
dpkg: unrecoverable fatal error, aborting
How to fix "dpkg: unrecoverable fatal error, aborting" in APT