How-to

sudo apt update: What It Does and How to Fix It

apt update does not update any software. It refreshes the list of what is available, so the next upgrade or install knows the latest versions.

What does apt update actually do?

It downloads the current package indexes from every repository configured on the machine and stores them locally. After it runs, apt knows which versions exist and which ones are newer than what is installed. Nothing on the system changes yet. It needs root because it writes to /var/lib/apt/lists, hence sudo apt update when you work as a normal admin user.

sudo apt update
sudo apt list --upgradable

The second line shows what an upgrade would change, with old and new versions side by side.

How do update, upgrade and full-upgrade differ?

CommandEffect
apt updateRefresh package lists only
apt upgradeInstall newer versions; may add new dependencies, never removes packages
apt full-upgradeLike upgrade, but may remove packages to resolve conflicts
apt autoremoveRemove dependencies nothing needs anymore

On a stable release, full-upgrade is mainly needed for kernel meta-packages and the occasional transition. It is also the command for moving between major releases, which deserves its own careful plan and a backup first.

Should scripts use apt or apt-get?

Scripts should use apt-get. The apt command is designed for people: progress bars, colors and output that may change between versions, and it prints a warning that its interface is not stable. apt-get update and apt-get -y upgrade behave the same way on every release, which is what automation needs. For unattended runs, also set DEBIAN_FRONTEND=noninteractive so no configuration prompt stops the job.

Where are repositories configured now?

In the deb822 format on current releases. Ubuntu 24.04 keeps its sources in /etc/apt/sources.list.d/ubuntu.sources and Debian 13 in /etc/apt/sources.list.d/debian.sources, with fields like Types, URIs, Suites, Components and Signed-By. The old one-line /etc/apt/sources.list style still works and is common on Debian 12 and Ubuntu 22.04. Third-party repositories should come with their own key file referenced by Signed-By; the old apt-key tool is deprecated.

Why does apt say it could not get the lock?

Another apt or dpkg process is running. On a freshly delivered machine this is very often unattended-upgrades doing its first security run, or the daily apt-daily timer. Wait a few minutes and try again. Check what holds the lock:

sudo fuser -v /var/lib/dpkg/lock-frontend
systemctl list-jobs | grep -i apt

Do not delete lock files to force your way in; interrupting dpkg halfway can leave packages broken. If a previous run was killed, sudo dpkg --configure -a finishes the half-done work.

What do other common errors mean?

  • "Release file is not valid yet": the system clock is behind. Check timedatectl and enable time sync with sudo timedatectl set-ntp true.
  • "NO_PUBKEY" or "The following signatures couldn't be verified": a third-party repository's key is missing or expired. Download the vendor's current key into /etc/apt/keyrings/ and reference it with Signed-By.
  • "Repository does not have a Release file": the repository path or suite name is wrong, often a third-party source that does not yet support your release.
  • "Hash Sum mismatch": a mirror was mid-update or a proxy changed the file. Clear lists with sudo rm -rf /var/lib/apt/lists/* and run update again.

How do I keep security updates automatic?

Use unattended-upgrades, which installs security updates daily. It is installed and active on Ubuntu by default; on Debian install it and turn it on:

sudo apt install unattended-upgrades
echo 'unattended-upgrades unattended-upgrades/enable_auto_updates boolean true' | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive unattended-upgrades
sudo unattended-upgrade --dry-run --debug | tail -20

A new kernel only runs after a restart. Check /var/run/reboot-required and reboot at a quiet hour; on our machines a reboot is one click in the panel or sudo systemctl reboot from SSH.

What about the Enterprise Linux images?

Rocky Linux, AlmaLinux and CentOS Stream use dnf, where dnf check-update lists updates and dnf upgrade applies them; metadata refresh happens automatically. FreeBSD uses pkg update and pkg upgrade for packages and freebsd-update for the base system. Running sudo itself is covered in The sudo command.

Keep Reading

The sudo command

How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.

Open

Ubuntu

Ubuntu 24.04 or 22.04 LTS on a whole machine: the default pick when you want the biggest pool of packages and how-tos.

Open

Debian

Debian 13 or 12 for servers that should change as little as possible between upgrades, on any machine we sell.

Open

Create a sudo user on Debian

Add an admin account on Debian 13 or 12, give it sudo rights, install your SSH key and retire daily root logins safely.

Open

FAQ

Quick Answers

No. It only refreshes the package lists. apt upgrade installs the newer versions.

upgrade never removes packages; full-upgrade may remove some to resolve dependency changes.

Another apt process, often unattended-upgrades, is running. Wait for it to finish instead of deleting lock files.

apt-get, because its output and behavior are stable for automation.

In /etc/apt/sources.list.d/debian.sources, using the deb822 format.