You've just logged into a fresh VPS, typed sudo apt install nginx (or htop, or php8.3-fpm, or whatever the tutorial said), and apt fires back E: Unable to locate package. Or apt update scrolls past a wall of 404 Not Found lines and finishes with "no longer has a Release file". Neither one means the package doesn't exist. It means apt doesn't know where to look. Here's how to find out which case you're in and fix it in a few minutes.

Symptom: what the errors look like

You'll usually hit one or more of these on Ubuntu or Debian:

E: Unable to locate package htop
E: Package 'php8.3-fpm' has no installation candidate
E: Couldn't find any package by glob 'python'
E: The repository 'http://archive.ubuntu.com/ubuntu mantic Release' no longer has a Release file.
Err:5 http://archive.ubuntu.com/ubuntu mantic-updates Release
  404  Not Found [IP: 91.189.91.82 80]

The first three are "apt can't find it in the lists it has". The last two are "the lists themselves can't be downloaded". They have different fixes, so read your output carefully before changing anything.

Cause: why apt can't find the package

apt only searches the package index files stored in /var/lib/apt/lists/. If a package isn't in those files, apt says it can't locate it, even if it's sitting on the mirror. That happens for a handful of reasons:

CauseTypical signQuick check
Package lists never downloadedFresh VPS image, nothing installsls /var/lib/apt/lists/ | wc -l is near zero
Component not enabled (universe, contrib, non-free)Core tools work, extras like htop or certbot don'tgrep -r universe /etc/apt/sources.list*
Wrong or renamed package nameOne specific package failsapt search <name>
Package needs a third-party repoSpecific PHP or Node versions, Docker CEapt-cache policy <name> shows nothing
Release is end-of-life404 / "no longer has a Release file"cat /etc/os-release

Fix: step by step

Step 1: Run apt update first (and actually read it)

Most minimal cloud images ship with empty or stale package lists to keep the image small. So the first move is always:

sudo apt update

Then try the install again. If it works, you're done. If apt update itself prints Err or 404 lines, jump to Step 5. Don't skip past those errors; a failed update leaves you with the same stale lists.

Step 2: Check the exact package name

Package names change between releases more often than people expect. A few classic traps:

  • python is gone on modern Ubuntu. Use python3 (and python-is-python3 if a script wants the old name).
  • mysql-server on Debian is replaced by mariadb-server.
  • PHP packages are versioned: php8.1-fpm on 22.04, php8.3-fpm on 24.04. Ask for the wrong one and you get "no installation candidate".
  • netstat lives in net-tools, dig lives in dnsutils (or bind9-dnsutils).

Search instead of guessing:

apt search php-fpm
apt-cache policy php8.3-fpm

If apt-cache policy prints Candidate: (none) or nothing at all, apt has no source for it. If you know the command but not the package, apt-file helps:

sudo apt install apt-file && sudo apt-file update
apt-file search bin/dig

Step 3: Enable the missing component

On Ubuntu, lots of everyday tools (htop, certbot on older releases, fail2ban on some images) live in universe. Some providers' images only enable main. Turn it on with:

sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update

Ubuntu 24.04 uses the newer deb822 format in /etc/apt/sources.list.d/ubuntu.sources. If you'd rather edit by hand, make sure the Components: line reads:

Components: main restricted universe multiverse

On Debian, the equivalent is adding contrib non-free non-free-firmware after main in /etc/apt/sources.list (or the Components: line in /etc/apt/sources.list.d/debian.sources on Debian 12+).

Step 4: Add the vendor repo when the distro doesn't ship it

Some versions simply aren't in the default archive. A newer PHP than your release ships, Docker CE, current Node.js, and MongoDB all need the vendor's own repository. Follow the vendor's install docs, which will have you drop a key into /etc/apt/keyrings/ and a .list or .sources file into /etc/apt/sources.list.d/, then run apt update.

Two things to watch out for here. First, use the repo built for your codename (lsb_release -cs tells you). A jammy repo on a noble box will either 404 or install packages that break later. Second, if the repo adds fine but apt complains about signatures, that's a separate GPG problem with its own fix, not a missing-package one.

Step 5: Fix 404s on an end-of-life release

This is the one that catches people on older VPSs. When an Ubuntu release reaches end of life, its packages get moved off archive.ubuntu.com to old-releases.ubuntu.com. Every apt update then 404s, and nothing installs. Interim releases (the ones ending in .10, and non-LTS .04s) only get nine months of support, so this happens faster than you'd think.

Confirm your release first:

cat /etc/os-release
lsb_release -a

If it's EOL, you've got two options:

  1. Upgrade (the right long-term fix). Point at old-releases temporarily, update, then run do-release-upgrade to step up to a supported release. Take a VPS snapshot before you start.
  2. Point at old-releases (short-term only). This gets apt working again so you can install what you need, but you won't get security updates.

Either way, the repoint looks like this:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i -E 's#https?://([a-z]{2}\.)?archive\.ubuntu\.com|https?://security\.ubuntu\.com#http://old-releases.ubuntu.com#g' /etc/apt/sources.list
sudo apt update

Debian works the same way, but the old repos live on archive.debian.org. For an archived release like Buster, replace deb.debian.org and security.debian.org with archive.debian.org and remove the -updates line, since it no longer exists. If apt then complains the Release file has expired, you can run sudo apt -o Acquire::Check-Valid-Until=false update once. Treat that as a stopgap while you plan the upgrade, not a permanent setting.

Step 6: Clear out a corrupted list cache

If apt update complains about hash sum mismatches or half-downloaded files, wipe the cache and pull it fresh:

sudo rm -rf /var/lib/apt/lists/*
sudo apt clean
sudo apt update

This is safe. Those files are only indexes, and apt rebuilds them straight away.

Step 7: Rule out the network

If every mirror times out rather than 404ing, the problem is connectivity or DNS, not apt. Try curl -I http://archive.ubuntu.com and getent hosts archive.ubuntu.com. If the name won't resolve, fix /etc/resolv.conf or your netplan DNS first. If outbound port 80 is blocked by your own firewall rules, open it or switch your sources to https:// mirrors.

Prevention

  • Run LTS releases on servers. Ubuntu LTS and Debian stable give you years of support instead of months.
  • Put EOL dates in your calendar. Plan the upgrade a couple of months early so you aren't doing it under pressure.
  • Make apt update your first command on every new VPS, before any installs.
  • Keep third-party repos tidy. Delete .list files in /etc/apt/sources.list.d/ for software you've removed, and update codenames after a release upgrade.
  • Snapshot before release upgrades. If do-release-upgrade goes sideways, rolling back takes minutes.

Frequently Asked Questions

Why does a package install on my laptop but not on my VPS?

They're probably on different releases, or your laptop has universe or a PPA enabled that the server image doesn't. Compare lsb_release -cs and apt-cache policy <package> on both.

Is it safe to keep using old-releases.ubuntu.com?

It works, but nothing there gets security patches. Use it to get through a release upgrade or a migration. Don't run an internet-facing server on it long term.

What does "has no installation candidate" mean?

apt knows the package name, usually because another package mentions it, but none of your enabled repos actually provide a version you can install. Enable the right component or vendor repo, or pick the correctly versioned name.

Will deleting /var/lib/apt/lists break anything?

No. It only holds downloaded index files. Your installed packages aren't touched, and apt update recreates everything.

Should I use apt or apt-get?

For typing commands yourself, apt is friendlier. In scripts, apt-get has a more stable output format. Both read the same sources and give the same "unable to locate" errors.