The 'package conflicts with package' error occurs when dpkg detects that two packages cannot be installed simultaneously because they declare mutual conflicts. This typically happens when multiple versions, variants, or incompatible software provide the same functionality. Resolve this by removing the conflicting package first or using apt to resolve dependencies automatically.
The "package conflicts with package" error in dpkg occurs when you attempt to install a package (.deb file) that has declared a "Conflicts" relationship with another already-installed package. In Debian/Ubuntu package management, a package can declare conflicts with other packages through its control metadata. This is a safety mechanism—two packages cannot be unpacked on the system simultaneously if one explicitly conflicts with the other. Common reasons for conflicts include: - Two different implementations of the same service (e.g., different mail servers or web servers) - Multiple versions of the same software that cannot coexist - Packages that claim the same files, ports, or system resources - Alternative package variants that serve the same purpose When dpkg detects this situation, it refuses to proceed with the installation to prevent system corruption or inconsistent state. The error message names both the conflicting package being installed and the already-installed package it conflicts with.
Read the error message carefully to see which packages are in conflict:
dpkg: regarding filename.deb containing package-name:
package-name conflicts with package-name2In this example:
- package-name: The package you're trying to install (from the .deb file)
- package-name2: The already-installed package that conflicts with it
List both packages to understand what they do:
# Check if the conflicting package is installed
dpkg -l | grep package-name2
# Get detailed information about each package
apt-cache show package-name
apt-cache show package-name2
# See which files belong to the installed package
dpkg -L package-name2Check the package metadata to see why they conflict:
# View the control information of the .deb file
dpkg-deb -I filename.deb | grep -E "Conflicts|Replaces|Provides"
# View control information of the installed package
apt-cache show package-name2 | grep -E "Conflicts|Replaces|Provides"Common reasons:
- Both packages provide the same command or service (check the "Provides:" field)
- Both packages contain files with the same path
- One package is meant to replace the other (check the "Replaces:" field)
- The packages implement incompatible versions of the same protocol or format
The safest solution is usually to remove the already-installed conflicting package first, then install the new package:
# First, understand what will be removed and why
apt-cache depends package-name2
apt-cache rdepends package-name2
# Remove the conflicting package
sudo apt-get remove package-name2
# Or more aggressively (removes it and packages that depend on it)
sudo apt-get remove --auto-remove package-name2
# Now install the new package
sudo dpkg -i filename.debBefore removing, check if anything depends on the conflicting package:
# Find packages that depend on the conflicting package
apt-cache rdepends package-name2
# Find packages that this one provides (often important)
apt-cache show package-name2 | grep ProvidesIf you're installing from a repository (not a local .deb file), apt can often resolve conflicts automatically:
# Let apt handle dependency and conflict resolution
sudo apt-get install package-name
# apt will either:
# 1. Remove the conflicting package automatically and install the new one
# 2. Suggest alternatives if the situation is ambiguous
# 3. Refuse if there's no safe resolution pathFor local .deb files, you can use gdebi (GUI) which handles dependencies better than raw dpkg:
# Install gdebi if not already present
sudo apt-get install gdebi
# Use gdebi to install the .deb (it will handle conflicts/dependencies)
sudo gdebi filename.debIf you're certain the packages can coexist, you can force dpkg to ignore the conflict. Only use this if you understand the consequences:
# Force dpkg to ignore conflicts (VERY RISKY)
sudo dpkg --force-conflicts -i filename.deb
# Or even more aggressive (overwrite files too)
sudo dpkg --force-all -i filename.debDangers of forcing:
- You may end up with two packages claiming the same files, causing data corruption
- Services may fail to start or behave unpredictably
- dpkg package database may become inconsistent
- Future updates may fail or break the system
Only use --force-conflicts if:
- You're packaging custom software and know exactly what will happen
- You're in a development environment and can rebuild if needed
- You have a recent backup and can recover from mistakes
If the installation partially succeeded but left the system in an inconsistent state, repair it:
# Configure any packages left in a broken state
sudo dpkg --configure -a
# Fix broken dependencies
sudo apt-get install -f
# Clean up the package cache
sudo apt-get clean
# Verify everything is consistent
sudo apt-get check
# Update package lists
sudo apt-get updateIf the system is severely broken:
# Remove the package that was forcibly installed
sudo dpkg -r package-name
# Reinstall the original conflicting package
sudo apt-get install package-name2
# Verify system health
sudo apt-get checkIf possible, install from the official or configured repositories instead of manually downloading a .deb file. apt is much smarter about resolving conflicts:
# Update package lists
sudo apt-get update
# Install from repository (apt will handle conflicts if possible)
sudo apt-get install package-name
# Check what apt wants to do before confirming
sudo apt-get install -s package-name # Simulate, don't actually installIf the conflicting package is newer:
# See available versions
apt-cache policy package-name
# Install a specific version
sudo apt-get install package-name=1.2.3
# Or prefer the newest version in a specific distribution
sudo apt-get -t bullseye install package-name### Understanding Debian Package Relationships
Debian packages use several relationship fields to define how they interact:
- Depends: Required for correct operation (must be installed)
- Recommends: Strongly suggested but not required
- Suggests: Optional enhancements
- Conflicts: Cannot be installed at the same time
- Replaces: This package supersedes another and can replace its files
- Provides: This package acts as a substitute for the named package
A "Conflicts" declaration is often paired with "Replaces"—the new package conflicts with the old one but declares it will replace the old package's files.
### Why Packages Conflict
File namespace issues: Only one package can own a given file. If both packages contain /usr/bin/mycommand, they implicitly conflict.
Service ports: Two web servers cannot both listen on port 80. Packages detect this and declare conflicts.
Configuration: Some packages manage the same configuration (e.g., default shell, default mail server) and cannot coexist.
API incompatibility: Major version differences may break each other's dependencies or plugins.
### Multiple Package Managers and Conflicts
Never mix dpkg and apt-get:
# Bad: Installing with dpkg then apt
sudo dpkg -i custom.deb
sudo apt-get install something-else # May break
# Good: Use apt-get consistently
sudo apt-get install something-elseapt (the newer tool) is much smarter about resolving conflicts and dependencies than raw dpkg. Whenever possible, use apt-get or apt instead of dpkg for installation.
### Checking for Hidden Conflicts
Some conflicts are implicit (shared files) rather than explicit (declared in metadata). Check what a package contains before installing:
# See what files a .deb file contains without installing
dpkg -c filename.deb | less
# See what files are already installed in a location
ls -la /usr/bin/ | grep mycommand
# Check which package owns an already-installed file
dpkg -S /usr/bin/mycommand### Resolving Complex Multi-Package Conflicts
For complex dependency graphs, use aptitude instead of apt-get:
# Install aptitude (interactive dependency resolver)
sudo apt-get install aptitude
# Use interactive mode to resolve conflicts
sudo aptitude install package-name
# aptitude will present multiple solutions and let you chooseAptitude is particularly good at finding less-obvious solutions when straight apt-get gives up.
### Common Package Conflict Patterns
| Pattern | Reason | Solution |
|---------|--------|----------|
| nginx vs apache2 | Both are web servers | Remove one, install the other |
| openjdk-8 vs openjdk-11 | Multiple Java versions | Multiple can coexist; check "Conflicts" field |
| sendmail vs postfix | Both are mail servers | Pick one mail server |
| exim4 vs other MTAs | Mail transport agents | Only one MTA can deliver locally |
| PHP versions (5.6 vs 7.4) | Incompatible PHP versions | Use php-distro packages to coexist; apt handles this |
### Recovering from Forced Installations
If you used --force-conflicts and the system is now unstable:
# Check the dpkg status
sudo dpkg --audit
# See what packages have issues
sudo apt-get check
# Force apt to fix broken packages
sudo apt-get install -f
# If that doesn't work, mark and remove the problematic package
sudo apt-mark hold package-name
sudo apt-get remove package-name
sudo apt-mark unhold package-nameE: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT