How to fix dpkg-divert: error: rename involves overwriting 'path' with different file in APT
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.
Quick fix
Fixes dpkg-divert: error: rename involves overwriting 'path' with different file
dpkg-divert --list- List all current diversions to understand the conflict
- Check for leftover conflicting files in diversion directories
- Attempt to remove the problematic diversion cleanly
- Manually move or remove the conflicting file
dpkg-divert --listdpkg-divert: error: rename involves overwriting 'path' with different file
What this error means
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.
Typical symptoms
- Package installation or upgrade fails with dpkg-divert error
- Specific files in /usr/lib or /usr/share cannot be managed by dpkg
- Multiple conflicting diversions reported for the same file
- System package manager (apt/aptitude) gets stuck trying to configure packages
Common causes
- Conflicting package diversions from incompatible packages (e.g., libgl1-mesa-swx11 with mesa-diversions)
- Leftover diverted files from previous failed installations remaining on disk
- Files from multiple packages attempting to manage the same path with different diversions
- Manual editing of /var/lib/dpkg/diversions file with unsupported syntax (e.g., adding comments)
- Package using Replaces field trying to remove a diversion created by another package
How to fix "dpkg-divert: error: rename involves overwriting 'path' with different file"
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.
Advanced notes
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
Frequently asked questions
- What does "dpkg-divert: error: rename involves overwriting 'path' with different" mean?
- 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.
- How do I fix "dpkg-divert: error: rename involves overwriting 'path' with different"?
- 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.
- What causes "dpkg-divert: error: rename involves overwriting 'path' with different"?
- Conflicting package diversions from incompatible packages (e.g., libgl1-mesa-swx11 with mesa-diversions) Leftover diverted files from previous failed installations remaining on disk Files from multiple packages attempting to manage the same path with different diversions
- Is the "dpkg-divert: error: rename involves overwriting 'path' with different" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐APT Official Documentation
- ๐
- ๐Ubuntu Manpage: dpkg-divert(8)(Official Docs)