What the message looks like
$ sudo apt install htop
Reading package lists... Done
Building dependency tree... Done
E: Unable to locate package htopCommon causes
apt updatewas never run, for example on a fresh server or in a new container, so the package lists are empty.- The package name is wrong, or the package has another name on your release.
- The repository component that carries the package is not enabled:
universeon Ubuntu,contribornon-freeon Debian. - The release is end of life and its repositories moved to an archive server, so
apt updateends with 404 errors. - A broken or typed-wrong entry in the sources makes
apt updatefail, so the lists stay incomplete.
Check
- Does apt know the package at all?
apt-cache policy htop - Search for the real package name
apt-cache search htop | head -n 10 - Which repositories and components are active?
grep -rE '^(deb |Types:|URIs:|Suites:|Components:)' /etc/apt/sources.list /etc/apt/sources.list.d/ 2>/dev/null - Which release is this?
cat /etc/os-release
Fix
- Refresh the lists and read the output for errors:
sudo apt update. - Use the exact package name that
apt-cache searchshows for your release. - Enable the missing component: on Ubuntu
sudo add-apt-repository universe, on Debian addcontribornon-freeto theComponentsof your sources, then runapt updateagain. - If
apt updateshows 404 for your release, it is end of life. Upgrade to a supported release instead of pointing the sources to an archive for production. - In a Dockerfile, run
apt-get updateandapt-get installin the sameRUNstep.
Typical scenario
Your Dockerfile starts with FROM ubuntu:24.04 and the next step is RUN apt-get install -y curl. The build stops with "E: Unable to locate package curl". The base image deliberately ships without package lists to stay small, so there is no information about which packages exist. Put apt-get update in front in the same RUN step so the layer cache does not keep an old, empty list.
FAQ
Why does it work on my laptop but not in the container?
Container images ship without package lists to stay small. Run apt-get update first, in the same build step as the install.
Is it safe to add third-party repositories to fix this?
Only if you trust the source. First check whether the package exists under another name or in an official component of your release.
What does apt-cache policy package show me?
It shows the installed version, the "Candidate" version and all sources with their priorities that the package could come from. If the Candidate line is empty or there is no output at all, apt does not know the package: the lists are empty or the right source is not enabled.
Why does apt find a package on Ubuntu 22.04 but not on 24.04?
Packages get renamed or removed between releases. Search with apt-cache search keyword or on the distribution's package search for the new name. For libraries the version number in the name often changes, such as libfoo1 to libfoo2.
How do I find the package that provides a certain command?
With apt-file search /usr/bin/command, after installing apt-file and running apt-file update. For an unknown command in the terminal, the helper package command-not-found often names the right package directly. That beats guessing package names.