How to fix dpkg-divert: error: rename involves overwriting 'path' with different file in APT

APTADVANCEDHIGHUpdated Dec 29, 2025ยท 201 views

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
  1. List all current diversions to understand the conflict
  2. Check for leftover conflicting files in diversion directories
  3. Attempt to remove the problematic diversion cleanly
  4. Manually move or remove the conflicting file
apt โ€” error
dpkg-divert --list
dpkg-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

  1. Conflicting package diversions from incompatible packages (e.g., libgl1-mesa-swx11 with mesa-diversions)
  2. Leftover diverted files from previous failed installations remaining on disk
  3. Files from multiple packages attempting to manage the same path with different diversions
  4. Manual editing of /var/lib/dpkg/diversions file with unsupported syntax (e.g., adding comments)
  5. 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"

1List all current diversions to understand the conflict

First, examine what diversions exist on your system:

bash
dpkg-divert --list

This will show all active diversions and help identify which file is causing the conflict. Look for the file mentioned in your error message.

2Check for leftover conflicting files in diversion directories

Look for orphaned files in common diversion directories:

bash
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.

3Attempt to remove the problematic diversion cleanly

If you identified the conflicting file, try to remove the diversion:

bash
dpkg-divert --remove /path/to/conflicting/file

If this works, the issue is resolved. If it still fails with the same error, proceed to the next step.

4Manually move or remove the conflicting file

If dpkg-divert --remove fails, you can manually remove the blocking file:

bash
sudo mv /usr/lib/xorg/modules/extensions/libglx.so /usr/lib/xorg/modules/extensions/libglx.so.backup

Replace 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:

bash
sudo apt update && sudo apt install -f
5Purge and reinstall affected packages as a last resort

If manual removal doesn't resolve the issue, completely remove and reinstall the conflicting packages:

bash
# 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-name

This 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