Anime-Sanctuary

Updates and packages with apt

A fresh server is never up to date: flaws have been fixed since it was built. Let's see the difference between apt update and apt upgrade, how to install a program, and how to let Debian apply security fixes by itself.

Course
Tutorial 10 of 35
Time
25 min to read
Tested with
Commands: tested on Debian 13.7 (trixie)
What you will be able to do
  • Update a Debian server with sudo, telling apt update from apt upgrade.
  • Search for, install and remove a package.
  • Turn on automatic security updates.

Before you start: Users, sudo and file permissions.

Contents
  1. The repository, or your server's catalog
  2. Refresh the catalog: apt update
  3. Install the new versions: apt upgrade
  4. Search for, install and remove a package
  5. When to reboot
  6. Automatic security fixes
  7. If it fails
  8. What's next
  9. Sources

How do you update Debian with apt, and why do it right away? Your server's system dates from the day your hosting provider built its template. Since then, flaws have been found and fixed, but those fixes aren't on your machine. We will fetch them, learn to install or remove a program, then hand the security fixes over to the machine. You type the commands in a terminal connected to your server (see Your first SSH connection), as alice, with the sudo set up in Users, sudo and file permissions.

The repository, or your server's catalog

A package is a program ready to install, and the repository is Debian's server that stores them all. Your machine doesn't browse that repository every time. It keeps its own copy of the catalog, which is the list of packages and their versions. A tool named apt reads that catalog to install and update things.

apt or apt-get?

In the previous article, one command used apt-get (apt-get install sudo). That is the older form of apt: same job, less readable output. Here we write apt everywhere.

That copy goes stale. So updating takes two separate steps, a bit like leafing through a bookshop's catalog before you place an order:

CommandWhat it doesChanges the system?
apt updatecopies the latest catalog from the repositoryno
apt upgradeinstalls the new versions of the packages already thereyes

The name update is misleading: it updates nothing, it only copies the catalog. Always run it first, or upgrade works from an outdated list.

1Refresh the catalog: apt update

Run apt update with sudo, because changing the system's catalog takes the powers of root, the machine's administrator. On your first sudo, type alice's password: nothing shows while you type, not even dots. That's on purpose, and your keyboard works. Finish with Enter.

On the server
sudo apt update
Expected output
Get:1 http://deb.debian.org/debian trixie InRelease [140 kB]
Get:2 http://deb.debian.org/debian-security trixie-security InRelease [43.4 kB]
Get:3 http://deb.debian.org/debian trixie/main amd64 Packages [9678 kB]
Get:4 http://deb.debian.org/debian-security trixie-security/main amd64 Packages [298 kB]
Fetched 10.2 MB in 1s (11.1 MB/s)
3 packages can be upgraded. Run 'apt list --upgradable' to see them.

This log scrolls by, and only the last line matters. Each Get line is a piece of the catalog being downloaded, and the addresses vary with the provider. The last line counts the packages that have a newer version. No line should start with Err: that signals an error, which some apt versions spell Error. Let's look at those packages before we touch them.

On the server
apt list --upgradable
Expected output
apt/stable-security 3.0.4 amd64 [upgradable from: 3.0.3]
libapt-pkg7.0/stable-security 3.0.4 amd64 [upgradable from: 3.0.3]
tzdata/stable-updates 2026f-0+deb13u1 all [upgradable from: 2026e-0+deb13u1]

Each line gives the package name, the version on offer, then the version installed on your machine. Your list depends on the day. Debian gives each release a name, here trixie, and a label, stable, stuck on the current release: for now, both mean the same Debian 13. The -security and -updates suffixes say where the fix comes from: security, or an ordinary update. Time to install those packages.

2Install the new versions: apt upgrade

The apt upgrade command installs every new version on that list. It first sums up what it is going to do, then asks for confirmation: answer Y, or press Enter.

On the server
sudo apt upgrade
Expected output
Upgrading:
  apt  libapt-pkg7.0  tzdata

Summary:
  Upgrading: 3, Installing: 0, Removing: 0, Not Upgrading: 0
  Download size: 2835 kB

Continue? [Y/n] Y
Fetched 2835 kB in 0s (24.0 MB/s)
Unpacking apt (3.0.4) over (3.0.3) ...
Setting up apt (3.0.4) ...

The Unpacking and Setting up lines mean a package is being unpacked, then configured. They repeat for each one, and the command hands control back when everything is done. One last apt update confirms there is nothing left to install.

On the server
sudo apt update
Expected output
Hit:1 http://deb.debian.org/debian trixie InRelease
Hit:2 http://deb.debian.org/debian trixie-updates InRelease
Hit:3 http://deb.debian.org/debian-security trixie-security InRelease
All packages are up to date.

"Hit" means the catalog hasn't changed since last time. "All packages are up to date" is what you were after. On a fresh machine, this routine takes a few minutes.

upgrade or full-upgrade?

The apt upgrade command never removes a package. When an update needs one removed or one added, it skips that update and reports it as "Not Upgrading". The apt full-upgrade command accepts those additions and removals: read its summary before you answer Y.

You know how to update what's there. Now let's add what isn't there yet.

3Search for, install and remove a package

apt search looks for a word in the catalog. Let's take tree, a small program that draws the contents of a folder. Copy the command as it is: it keeps only the package named exactly tree, or the list would be very long.

On the server
apt search --names-only "^tree$"
Expected output
tree/stable 2.2.1-1 amd64
  displays an indented directory tree, in color
What do ^ and $ mean in the command?

In "^tree$", the ^ sign means "the name starts here" and $ means "the name ends here". The --names-only option limits the search to package names.

The first line gives the name and the version, the second describes the program. Let's install it, with sudo because installing takes the powers of root.

On the server
sudo apt install tree
Expected output
Installing:
  tree

Summary:
  Upgrading: 0, Installing: 1, Removing: 0, Not Upgrading: 0
  Download size: 59.4 kB

Get:1 http://deb.debian.org/debian trixie/main amd64 tree amd64 2.2.1-1 [59.4 kB]
Fetched 59.4 kB in 0s (3886 kB/s)
Unpacking tree (2.2.1-1) ...
Setting up tree (2.2.1-1) ...

Here apt asked no question: installing a single package without changing anything else needs no confirmation. As soon as apt has to touch something else, or for upgrade and remove, it shows Continue? [Y/n]: read its summary before you answer. The program is ready, so let's create two subfolders and two empty files, then draw the result. The mkdir -p command creates folders (-p avoids an error if they already exist), and touch creates an empty file. They appear in your home folder, where your session opens.

On the server
mkdir -p demo/photos demo/docs
touch demo/docs/cv.txt demo/photos/chat.jpg
tree demo
Expected output
demo
|-- docs
|   `-- cv.txt
`-- photos
    `-- chat.jpg

3 directories, 2 files

Don't need it anymore? Remove it with apt remove, which asks for confirmation. The demo test folder can go too: rm -r demo deletes it.

On the server
sudo apt remove tree
Expected output
REMOVING:
  tree

Summary:
  Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 0
  Freed space: 132 kB

Continue? [Y/n] Y
Removing tree (2.2.1-1) ...
autoremove and purge
  • sudo apt autoremove removes the packages that only existed to serve a package you have since removed.
  • sudo apt purge tree removes the program and its settings files, whereas remove keeps them in case you reinstall it.

You can now manage packages. One last step may still be needed for an update to take effect.

When to reboot

You only need to reboot after an update of the kernel, the core of the system. If a name starting with linux-image (for example linux-image-6.12.48-amd64) appears in the apt upgrade list, reboot. This article's list has none, so there is no hurry in that case.

To reboot, one command is enough. Linux keeps running the old kernel until the machine restarts.

On the server
sudo reboot

Your remote connection (SSH) drops, which is normal. Pick a quiet moment, because the server is down for a minute or two. Then reconnect with the command you usually use, here alice's:

On your computer
ssh alice@203.0.113.10

Read it aloud as "ssh, alice, at, 203 dot 0 dot 113 dot 10": alice is the user, and the string of numbers is the server's address.

Automatic security fixes

The unattended-upgrades package installs Debian's security fixes on its own, every day. That's useful: a known flaw stays exploitable as long as the fix is missing, and bots hunt for it the day after it is announced. Let's install it.

On the server
sudo apt install unattended-upgrades

On Debian, installing it already turns it on, as two lines of settings prove:

On the server
cat /etc/apt/apt.conf.d/20auto-upgrades
Expected output
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

The first line refreshes the catalog, the same job as apt update. The second installs the fixes, the same job as apt upgrade. The 1 means "every day". To see what the machine would do, run a "dry run", which changes nothing:

On the server
sudo unattended-upgrade --dry-run -v
Expected output
Starting unattended upgrades script
No packages found that can be upgraded unattended and no pending auto-removals

The last line says there is nothing to install today. If fixes are waiting, a Packages that will be upgraded line names them instead. Each night's report is in /var/log/unattended-upgrades/.

If it fails

The apt messages are clear, and three come up most often:

  • Could not open lock file ... (13: Permission denied): you forgot sudo in front of apt install or apt update. Run the command again with sudo.
  • Unable to locate package arbre-magique: the name has a typo, or it isn't in the catalog. Look for it with apt search. If you're sure of the name, run sudo apt update first.
  • Could not get lock ...: another update is already running, often the automatic one. Wait a few minutes and try again. Don't delete the lock file: it stops two installs from running at once.

What's next

Your server is up to date, and security fixes will install themselves. Only a new kernel will need a reboot from you. But anyone on the Internet can still try alice's password, and that's the most exposed door. The next article, Secure SSH: turn off passwords, replaces it with a key nobody can guess and shuts the password login.

Sources (accessed November 4, 2026)

  • Debian: apt(8), Debian wiki, UnattendedUpgrades.
  • Commands: tested on Debian 13.7 (apt 3.0, unattended-upgrades 2.12). sudo reboot and dpkg --configure -a follow the documentation and weren't replayed here.