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.
Stop reading, start building
This pairs with a hands-on BytExplorer course — do it on your own machine and actually keep the skill.