How to fix dpkg: dependency problems prevent removal of linux-image-X.X.X-generic in APT
This error occurs when dpkg cannot remove a Linux kernel package due to unmet dependencies or broken package states. Fix it by repairing dependencies with apt, configuring pending packages, or manually removing old kernels to free /boot space.
Quick fix
Fixes dpkg: dependency problems prevent removal of linux-image-X.X.X-generic
uname -r- Check your current kernel version
- Repair broken dependencies with apt
- Configure any pending packages
- List installed kernels
uname -rdpkg: dependency problems prevent removal of linux-image-X.X.X-generic
What this error means
The dpkg package manager is refusing to uninstall a Linux kernel image package (like linux-image-5.4.0-42-generic) because other packages depend on it or the package management system is in a broken state. This typically happens during kernel upgrades when your /boot partition is full, or when DKMS modules (like wireguard) are incompatible with the kernel version you're trying to remove. The error indicates that dpkg has detected unmet dependencies that would be violated if it allowed the removal.
Typical symptoms
- apt or dpkg commands fail when trying to remove or upgrade kernel packages
- /boot partition shows "No space left on device" errors during updates
- System cannot install pending kernel or driver updates
- Automatic kernel cleanup fails during distribution upgrades
- Multiple old kernel versions accumulate and cannot be removed
- DKMS module compilation fails during kernel installation
Common causes
- /boot partition is full because multiple old kernel versions are installed and consuming space
- Package management system is in a broken state due to interrupted installations or upgrades
- DKMS modules (like wireguard, nvidia-driver) do not match the kernel version and prevent removal
- Another package explicitly depends on the linux-image package version you are trying to remove
- dpkg was interrupted during a previous operation and left packages in an unconfigured state
- Conflicting package versions or failed dependency resolution during updates
How to fix "dpkg: dependency problems prevent removal of linux-image-X.X.X-generic"
First, identify which kernel you are currently running so you do not accidentally remove it:
uname -rThis outputs something like 5.15.0-86-generic. Do NOT remove this kernel as it will make your system unbootable.
Try the most straightforward fix first - repair any broken dependencies and configure unconfigured packages:
sudo apt --fix-broken installIf that succeeds, your issue is resolved. If not, proceed to the next step.
If dpkg was interrupted during a previous operation, configure any unconfigured packages:
sudo dpkg --configure -aThen try the fix again:
sudo apt --fix-broken installIf the above steps do not work, check which kernel versions are installed on your system:
dpkg -l | grep linux-imageThis shows all installed kernel packages. Identify old versions that you can safely remove (anything except your current kernel from Step 1).
Once you identify an old kernel to remove, use dpkg to force-purge it:
sudo dpkg --purge --force-all linux-image-5.4.0-42-genericReplace 5.4.0-42-generic with the actual old kernel version. The --force-all flag overrides dependency checks. After removing one or two old kernels, proceed to the next step.
After manually removing old kernels, fix any remaining broken dependencies:
sudo apt-get -f installThen update your package cache and try to complete any pending operations:
sudo apt-get update
sudo apt-get upgradeFinally, clean up any leftover package configuration files and perform automatic removal of unused packages:
sudo dpkg -P $(dpkg -l | grep ^rc | awk '{print $2}')
sudo apt-get autoremoveThis removes packages marked for removal and cleans up the system.
Advanced notes
For most systems, keep only 2 kernel versions installed: the currently running kernel and the immediately previous one. This provides a fallback if a kernel update breaks your system. The /boot partition is typically small (200-500MB) and runs out of space quickly with multiple kernel versions since each kernel includes compressed images, initramfs files, and DKMS modules. On systems with LVM, encrypted filesystems, or other storage constraints, managing kernel count is especially critical. If you prefer a more automated approach, use sudo apt autoremove which safely removes old kernels while keeping at least the current and previous versions. For DKMS-related failures, check if DKMS modules are compatible with your target kernel using dkms status before attempting removal.
Frequently asked questions
- What does "dpkg: dependency problems prevent removal of linux-image-X.X.X-generic" mean?
- 0-42-generic) because other packages depend on it or the package management system is in a broken state. This typically happens during kernel upgrades when your /boot partition is full, or when DKMS modules (like wireguard) are incompatible with the kernel version you're trying to remove. The error indicates that dpkg has detected unmet dependencies that would be violated if it allowed the removal.
- How do I fix "dpkg: dependency problems prevent removal of linux-image-X.X.X-generic"?
- This error occurs when dpkg cannot remove a Linux kernel package due to unmet dependencies or broken package states. Fix it by repairing dependencies with apt, configuring pending packages, or manually removing old kernels to free /boot space.
- What causes "dpkg: dependency problems prevent removal of linux-image-X.X.X-generic"?
- /boot partition is full because multiple old kernel versions are installed and consuming space Package management system is in a broken state due to interrupted installations or upgrades DKMS modules (like wireguard, nvidia-driver) do not match the kernel version and prevent removal
- Is the "dpkg: dependency problems prevent removal of linux-image-X.X.X-generic" 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: RemoveOldKernels community documentation(Official Docs)