Debian/Ubuntu: Fix 'Could Not Calculate Upgrade' Error
This happens when apt's package dependency solver can't find a valid upgrade path. Usually from mixed repos or held packages. Real fix: clean sources and unhold.
Quick answer: Run sudo apt-mark unhold $(apt-mark showhold), then sudo apt update && sudo apt upgrade. If that fails, check /etc/apt/sources.list for mixed releases.
What's actually happening here?
The Could not calculate upgrade error means apt's dependency resolver hit a wall. It can't find a consistent set of package versions to upgrade to. This isn't a network or disk problem—it's a logic problem in your package sources or package states.
Common real-world triggers:
- You added a PPA or third-party repo that ships packages conflicting with the distro's versions.
- You manually installed a
.debfile from a different release (e.g., Ubuntu 22.04 package on 20.04). - You accidentally left a
testingorsidentry in yoursources.listwhile running stable. - You pinned a package with
apt-mark holdand the held version doesn't match the repo's dependency tree.
The fix isn't just one command. You need to identify what's confusing apt.
Step-by-step fix
1. Clean and update sources
sudo apt clean
sudo apt autoclean
sudo apt update
This clears the package cache and fetches fresh metadata. If the error persists, your repo list is the problem.
2. Find held packages
apt-mark showhold
Held packages are the #1 cause. If you see any listed, unhold them all with:
sudo apt-mark unhold $(apt-mark showhold)
Then run sudo apt upgrade again. If it works, you can re-hold packages after the upgrade—but only if you're sure they won't cause issues.
3. Check for mixed sources
Look at /etc/apt/sources.list and files in /etc/apt/sources.list.d/. You should never have entries for both stable and testing in the same repo. Example of wrong:
deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bookworm main
If you see something like that, comment out the wrong one with #, then update and upgrade.
4. Dry-run with apt-get
apt-get -s upgrade shows what would happen without actually doing it. Look for lines like Conflicts:... or Broken:.... That tells you exactly which package is causing the failure.
Alternative fixes if main one fails
Option A: Force dist-upgrade (risky)
sudo apt-get -f install
sudo apt-get dist-upgrade
dist-upgrade is smarter about removing conflicting packages. But it can also remove packages you want. Check the list before confirming. I'd only do this if you're confident in your backup.
Option B: Pin the problematic package to a specific version
If a single package from a PPA is blocking everything, pin it to the distro version:
sudo apt install package-name=version-number-from-official-repo
Find the correct version with apt policy package-name. Then lock it with apt-mark hold if needed.
Option C: Disable all third-party repos
Temporarily rename /etc/apt/sources.list.d/ to something else, update, and try the upgrade. If it works, you know one of those repos is the problem. Add them back one by one.
How to prevent this
- Never mix Debian stable/testing/sid in the same system. Each release has its own package versions and dependency trees. Mixing them is asking for this error.
- Don't hold packages unless you have a good reason. And if you do, test the upgrade with
apt-get -sfirst. - Use PPAs sparingly. Only add repos you actually need, and remove them when you don't.
- Check
/etc/apt/preferences.d/for any custom pinning files. They can override repo priorities and cause the solver to fail.
One more thing: If you're on Ubuntu and you see this after upgrading from 20.04 to 22.04 or 24.04, your
sources.listlikely still has the old codename. Changefocaltojammy(orjammytonoble), then runsudo apt update && sudo apt upgrade.
Was this solution helpful?