apt: E: Unable to locate package
apt install fails with 'E: Unable to locate package' for something you know exists. Usually your package list is just stale, or the package lives in a repo you haven't enabled. Here's the fix order.
You try to install something and apt shrugs:
E: Unable to locate package nginx
apt doesn't search the internet — it searches a local index of what's available from your configured repositories. This error means the package name isn't in that index. Almost always the index is just out of date, the name is slightly off, or the package lives in a repo you haven't turned on.
Step 1: Update the package list (fixes it most of the time)
A fresh system, or one that hasn't updated in a while, has an empty or stale index. Refresh it first:
sudo apt update # re-downloads the list of available packages
sudo apt install nginx
On a brand-new container or VM this single step resolves the error the majority of the time.
Step 2: Check the exact package name
apt names are precise and case-sensitive. docker isn't docker.io; nodejs isn't node. Search for what actually exists:
apt search <keyword> # find the real package name
apt-cache policy <package> # confirm it's available and from where
Step 3: Enable the repo the package lives in
On Ubuntu, many packages live in the universe component, which may not be enabled:
sudo add-apt-repository universe
sudo apt update
Some software ships from the vendor's own repository (Docker, Node.js, PostgreSQL). For those, you must add their repo first — check the project's install docs.
Reach for
apt updatebefore you conclude a package "doesn't exist". A stale index is the cause far more often than a genuinely missing package.
Step 4: Right tool, right distro
apt is Debian/Ubuntu. If you're on Fedora/RHEL the command is dnf, and on Alpine it's apk. Running apt on the wrong distro produces the same confusion.
The checklist
sudo apt update— refresh the index first.apt searchto confirm the exact name.- Enable
universe(Ubuntu) or add the vendor's repo. - On the right distro?
dnf/apkelsewhere.
Frequently Asked Questions
What does "E: Unable to locate package" mean?
apt doesn't have that package in its index — usually the package list is stale, the name is misspelled, or the repository component that provides it (like universe) isn't enabled.
How do I fix "unable to locate package"?
Run sudo apt update first to refresh the index, double-check the exact package name, and enable extra components if needed (sudo add-apt-repository universe). Then retry the install.
Why does it happen on a fresh WSL, Docker, or cloud image?
Minimal images ship with an empty package index, so apt knows about nothing until you run sudo apt update. That first update is almost always the fix.
Stop reading, start building
This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.