The 30-second fix: refresh your package lists
What's actually happening here is that apt works off a local cache of package names and versions. That cache lives in /var/lib/apt/lists/. If it's empty or stale, apt literally has no idea the package you want exists — even if the package is in the official repos.
Run this first:
sudo apt updateThat command pulls the latest package lists from every repo configured in /etc/apt/sources.list and /etc/apt/sources.list.d/. Wait for it to finish — you'll see a bunch of Get: lines. Then retry your install.
This fixes the majority of cases. I've hit this more often on fresh Docker containers and new VPSes than anywhere else, because those images ship with a stripped-down apt cache. Don't skip this step even if you've run it recently — repos update constantly, and a package you tried an hour ago might be available now.
The 5-minute fix: enable the universe and multiverse repos
If apt update didn't help, the package might live in a repo that isn't enabled by default. On Ubuntu, that's usually universe — the community-maintained repo — or multiverse, which holds software with licensing restrictions.
Check your current sources:
grep -R "^deb" /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/nullLook for lines that mention main restricted. If you see only those, you're missing universe. The easiest fix is:
sudo add-apt-repository universe
sudo apt updateIf add-apt-repository isn't installed (common on minimal installs), do it manually:
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe"
sudo apt updateThe $(lsb_release -sc) part inserts your Ubuntu codename automatically, so you don't have to remember whether you're on jammy or noble. The reason this works: apt's package lists are per-repo, and a package won't appear until its repo's list is downloaded. Enabling the repo and running update makes that happen.
For Debian, the same logic applies — you might need contrib or non-free sections. Edit /etc/apt/sources.list and add those to your existing lines, then run sudo apt update.
The 15+ minute fix: verify the package name and repo configuration
Still stuck? The package might not exist under that name, or you might be looking at a package from a third-party repo that isn't configured. Don't guess — search first.
apt-cache search <your-keyword>That prints a list of every package whose name or description matches. For example, apt-cache search python3-requests will show you the exact name. Often people type python-requests when the actual package is python3-requests. One character makes the difference.
If the search returns nothing, the package isn't in any of your configured repos. That doesn't mean it doesn't exist — it might be in a PPA or a vendor repo. For instance, to install nginx on Ubuntu 20.04, the default repo has it, but to get the latest version you'd add the nginx repo manually:
sudo add-apt-repository ppa:nginx/stable
sudo apt update
sudo apt install nginxThe same pattern applies to any third-party software: add their repo key, add the repo, update, install. Check the vendor's docs for the exact commands.
One more thing to check: architecture mismatches. If you're on a 64-bit system but the package is only compiled for 32-bit, apt won't find it. Run dpkg --print-architecture to confirm. If you need to add a 32-bit architecture, that's sudo dpkg --add-architecture i386 — but that's rare, and I'd only do it if you specifically need that package.
A quick note on those
Errlines duringapt update: if a repo fails to reach its server, its package list won't refresh. That repo's packages will show as "unable to locate" until the server is reachable. Fix the network issue first, then update again.
The whole flow takes under a minute if you're lucky, and under 20 minutes if you're chasing a PPA. Start at the top, stop when the package installs. Don't jump to the advanced steps unless you've actually tried the earlier ones — they're cheap to run and usually solve the problem.