Fixing dpkg "trying to overwrite" Errors After a Botched Mono Removal on Ubuntu

Abstract: A partial Mono uninstall can leave dpkg in a broken state where apt refuses to install or upgrade anything. This guide explains why the file-overwrite conflict happens and walks through a safe, step-by-step repair.

Created: 2026-11-02 by

If sudo apt --fix-broken install fails with a dpkg message about one package "trying to overwrite" a file that already belongs to another package — commonly a .dll under /usr/lib/mono/gac/ — your system is stuck with two Mono packages that both claim the same file, usually because a removal was interrupted or because Mono packages from two different repositories are installed side by side. The fix is not to reinstall the conflicting package, but to force-purge the broken set of Mono packages, repair dpkg's internal state, and then let apt settle everything cleanly.

Why This Happens

Dpkg does not allow two packages to own the same file path (with a few sanctioned exceptions for cooperating packages). The error in this situation typically looks like this:

dpkg: error processing archive /var/cache/apt/archives/mono-libraries_...deb (--unpack):
trying to overwrite '/usr/lib/mono/gac/Accessibility/.../Accessibility.dll',
which is also in package libmono-accessibility4.0-cil

There are two common root causes:

  • Mixed package sources. Mono ships both in Ubuntu's own repositories and in third-party repositories (such as the official Mono project's). If you install Mono from one source and then partially install or upgrade from the other, the two package sets overlap and fight over the same GAC paths.
  • Interrupted removal or upgrade. If you ask apt to remove Mono while related packages (runtimes, development libraries, applications that depend on it) are still half-configured, dpkg can end up with packages marked installed that no longer have consistent contents.

A key diagnostic clue is the output of apt policy: if an installed package's version string contains a repository suffix (like 0xamarin2+ubuntu2004b1) but that version no longer appears in any configured repository's version table — only in /var/lib/dpkg/status — you have an orphaned package from a repo you no longer use. That stale package is what collides with the new one apt is trying to unpack.

Note that manually deleting the conflicting file, as many people try first, does not help. Dpkg's error is about package ownership metadata, not the file on disk; dpkg simply refuses the unpack operation before it even checks whether the file exists.

Step 1: Finish Pending Configuration

Before touching individual packages, let dpkg resolve whatever half-finished transactions are pending:

sudo dpkg --configure -a

If this itself errors out on Mono packages, that is expected — continue to the next step.

Step 2: Force-Purge the Broken Mono Packages

Purge the package that owns the conflicting file and its siblings, ignoring dependency complaints for now:

sudo dpkg --force-all --purge mono-libraries
sudo dpkg --force-all --purge mono-devel mono-runtime mono-libraries-debug \
  liblog4net1.2-cil keepass2-plugin-hibpofflinecheck

The exact package list depends on what is installed on your machine. Use dpkg -l | grep -i mono to find every Mono-related package, and include any applications that pulled them in (for example, a 3D-printing host application or a password-manager plugin). --force-all is aggressive, but here it is justified: these packages are already inconsistent, and you need dpkg to forget them entirely.

Errors during this step — dependency complaints, "package is in a very bad inconsistent state" messages — can be safely ignored as long as the purge ultimately completes.

Step 3: Clean Up with apt

Now let apt catch anything dpkg missed and repair dependency state:

sudo apt purge mono-libraries mono-devel mono-runtime
sudo dpkg --configure -a
sudo apt update
sudo apt --fix-broken install

If --fix-broken install tries to reinstall the Mono libraries again, that means something still depends on them. Either purge that dependent application as well, or — if you actually want Mono — make sure all Mono packages come from a single repository so the file ownership conflict disappears.

What Not to Do

  • Do not delete files by hand. Removing the conflicting .dll or GAC directory does nothing, because the error is about dpkg's package database, not the filesystem.
  • Do not force-purge unrelated libraries. --force-all on non-Mono packages can break core desktop components and leave the system in worse shape. Keep the force-purge strictly scoped to the conflicting set.
  • Do not keep mixing Mono sources. Pick one — Ubuntu's universe repository or the official Mono repository — and stick with it.

Preventing a Recurrence

Before removing a metapackage or a framework like Mono, check what depends on it with apt rdepends --installed <package> or review apt's proposed transaction carefully instead of confirming blindly. When a removal goes wrong, stop and diagnose with apt policy and dpkg -l rather than attempting repeated install/remove cycles, which tend to deepen the inconsistency. Finally, if you have ever added a third-party repository, remove stale packages from it before switching sources — orphaned packages with no matching repository version are the most common trigger for overwrite conflicts like this one.

Frequently Asked Questions

Why did deleting the conflicting DLL not fix anything?

Dpkg rejects the unpack based on its package ownership database, not on the actual file contents. If two packages claim the same path, the error occurs regardless of whether the file exists on disk. Only purging one of the conflicting packages resolves the ownership conflict.

Is dpkg --force-all dangerous?

It can be, which is why it should be limited to the specific broken packages you are trying to remove. Used narrowly to purge an inconsistent package set, it is a standard recovery tool; used broadly, it can remove packages the system genuinely needs.

How do I find all Mono-related packages on my system?

Run dpkg -l | grep -i mono for packages with "mono" in the name, and also look for common Mono-dependent applications ( KeePass plugins, log4net libraries, certain printing or 3D-printing software). Those dependent packages often need to be purged in the same pass.

What does the repository suffix in a version string mean?

Strings like 0xamarin2+ubuntu2004b1 indicate the package was built for or distributed by a specific repository, in this case the upstream Mono project's Ubuntu packages. If apt policy shows that version only under /var/lib/dpkg/status and not under any configured repository, the package is orphaned and is a likely source of conflicts.

Can I reinstall Mono afterwards?

Yes. Once dpkg is consistent again and apt --fix-broken install completes without errors, install Mono from a single repository of your choice. Avoid mixing the Ubuntu-packaged versions with the upstream project's repository packages, since that is a frequent cause of this exact conflict.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More