On Linux you rarely download an installer from a website. Software arrives as packages from repositories your distribution maintains, signs and patches for years. That is what makes a server reproducible: “install nginx” means the same tested build on every machine, and a security fix for OpenSSL reaches all of them with one command. For a DevOps engineer, package management is daily work: provisioning VMs, writing Dockerfiles, patching fleets and answering “which version is running where?”.
In this lesson you learn how packages, repositories and dependencies fit together, use apt and dpkg on Ubuntu, keep a version from changing, add a third-party repository without weakening security, turn on automatic security updates and know when a reboot is due. You finish by installing nginx for Orbit, plus the dnf and apk commands for the other families.
Note: use the Multipass VM for this lesson. A container works for most commands, but services such as nginx and unattended-upgrades need systemd.
Packages, repositories and dependencies
A package is an archive of files (programs, libraries, default configuration, documentation) plus metadata: name, version, a description and the list of other packages it needs. Ubuntu and Debian use .deb packages; the Red Hat family uses .rpm; Alpine uses .apk.
A repository is a web server that publishes packages together with an index of everything it offers. That index is signed with the distribution’s GPG key, and your package manager refuses data it cannot verify. This is what keeps a compromised mirror from slipping you a tampered openssl.
Dependencies are why you use a package manager instead of copying files. nginx needs a TLS library, a compression library and a few shared helper packages; the package manager works out the whole set, installs what is missing and later knows which ones nobody needs anymore.
| Layer | Ubuntu, Debian | RHEL, Rocky, Alma, Fedora | Alpine |
|---|---|---|---|
| High-level tool (repositories, dependencies) | apt | dnf | apk |
| Low-level tool (single package files) | dpkg | rpm | apk |
| Package format | .deb | .rpm | .apk |
apt on Ubuntu
update, upgrade and full-upgrade
These three are confused more than any other commands in Linux:
| Command | What it does |
|---|---|
sudo apt update | Downloads fresh repository indexes. Installs nothing |
sudo apt upgrade | Upgrades installed packages; may install new dependencies, never removes anything |
sudo apt full-upgrade | Upgrades and may also remove packages when that is the only way to resolve a change |
Always update first: the package manager only knows the versions listed in its last downloaded index.
$ sudo apt update
...
12 packages can be upgraded. Run 'apt list --upgradable' to see them.
$ apt list --upgradable
openssl/resolute-security 3.5.3-1ubuntu1.1 amd64 [upgradable from: 3.5.3-1ubuntu1]
Then sudo apt upgrade applies them. Your version numbers will differ. resolute is the codename of Ubuntu 26.04; resolute-security is the pocket that carries security fixes.
Install, inspect and remove
apt search --names-only '^nginx' finds packages by name and apt show nginx describes one. Installing lists what will change before it asks:
$ sudo apt install nginx
Installing:
nginx
Installing dependencies:
nginx-common
Summary:
Upgrading: 0, Installing: 2, Removing: 0, Not Upgrading: 12
Download size: 640 kB
Space needed: 1,940 kB / 6,400 MB available
Continue? [Y/n]
APT 3, which ships with Ubuntu 26.04, prints this tidier summary; older releases show a denser text block with the same information. To remove software you have three levels:
sudo apt remove nginxremoves the program but keeps its configuration in/etc, so a later reinstall picks it up again.sudo apt purge nginxremoves the program and its configuration files.sudo apt autoremoveremoves dependencies that were installed automatically and are no longer needed by anything.
apt list --installed lists everything installed (pipe it to grep), and apt-cache policy nginx shows the installed version, the candidate apt would install and which repository each version comes from:
$ apt-cache policy nginx
nginx:
Installed: 1.28.0-4ubuntu2
Candidate: 1.28.0-4ubuntu2
Version table:
*** 1.28.0-4ubuntu2 500
500 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages
100 /var/lib/dpkg/status
The 500 is the priority of each source; *** marks what is installed. When a vendor repository offers a newer version, this is where you see which one wins.
Tip: in scripts and Dockerfiles use apt-get, not apt. apt is designed for humans and warns that its output may change; apt-get has a stable interface. A typical non-interactive install is sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends nginx, where --no-install-recommends skips optional extras.
Holding and pinning versions
Sometimes a package must not move: a database whose major upgrade needs planning, or a library your app was tested against. Hold it and apt upgrade leaves it alone:
$ sudo apt-mark hold postgresql-18
postgresql-18 set on hold.
apt-mark showhold lists held packages and sudo apt-mark unhold postgresql-18 releases one. To install one specific version, append =version: sudo apt install nginx=1.28.0-4ubuntu2. To keep preferring a version or repository over time, use a pin in /etc/apt/preferences.d/, for example /etc/apt/preferences.d/nginx:
Package: nginx nginx-common
Pin: version 1.28.*
Pin-Priority: 1001
A priority above 1000 even allows a downgrade to the pinned version. Check the effect with apt-cache policy nginx. Remember to remove holds and pins later: a forgotten hold is how servers end up years behind on security fixes.
dpkg: the low-level view
dpkg works on what is installed, without repositories. Three questions it answers instantly:
$ dpkg -l 'nginx*'
ii nginx 1.28.0-4ubuntu2 amd64 small, powerful, scalable web/proxy server
ii nginx-common 1.28.0-4ubuntu2 all small, powerful, scalable web/proxy server - common files
$ dpkg -L nginx-common | grep nginx.conf
/etc/nginx/nginx.conf
$ dpkg -S /usr/sbin/nginx
nginx: /usr/sbin/nginx
dpkg -llists packages;iiin the first column means “desired: install, status: installed”.rcmeans removed but configuration left behind (a candidate forpurge).dpkg -L packagelists the files a package installed.dpkg -S pathtells you which package owns a file. Perfect for “where did this binary come from?”.
To install a downloaded .deb, use sudo apt install ./file.deb rather than dpkg -i: apt resolves its dependencies too.
Repositories and sources
Ubuntu 24.04 and later describe repositories in the deb822 format, in /etc/apt/sources.list.d/ubuntu.sources instead of the old one-line sources.list:
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: resolute resolute-updates resolute-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: resolute-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Each block is a source. Suites are release pockets: the base release, -updates (bug fixes), -security and -backports (newer versions, opt-in). Components sort packages by support: main is maintained by Canonical, universe by the community. Signed-By names the only key allowed to sign this source.
Adding a third-party repository safely
Vendors such as database, monitoring or CI tool makers publish their own apt repositories. The safe pattern ties the vendor’s key to the vendor’s repository only. Here with a placeholder vendor at packages.example.com; real vendors document the same steps with their own URLs:
$ sudo install -d -m 0755 /etc/apt/keyrings
$ curl -fsSL https://packages.example.com/apt/key.asc | sudo tee /etc/apt/keyrings/example.asc > /dev/null
$ gpg --show-keys /etc/apt/keyrings/example.asc
Compare the fingerprint gpg prints with the one in the vendor’s documentation. Then create /etc/apt/sources.list.d/example.sources:
Types: deb
URIs: https://packages.example.com/apt
Suites: stable
Components: main
Architectures: amd64
Signed-By: /etc/apt/keyrings/example.asc
Run sudo apt update and the new source appears. Why this way: a key in /etc/apt/keyrings referenced by Signed-By can only vouch for that one repository. The old apt-key add trusted a key for every repository on the system, which is why it was deprecated and has disappeared from current releases.
Warning: never “fix” signature errors with trusted=yes or [allow-insecure=yes], and be wary of curl ... | sudo bash installers. Each one hands root on your server to whoever controls that URL. Every added repository can replace any package on the system, so add only vendors you trust and remove the ones you stop using.
For Ubuntu PPAs (personal package archives), sudo add-apt-repository ppa:owner/name performs the same key and source steps for you.
Automatic security updates
Ubuntu Server ships with unattended-upgrades, which installs packages from the -security pocket once a day. Check that it is active:
$ cat /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
$ sudo unattended-upgrade --dry-run --debug | tail -3
Policy lives in /etc/apt/apt.conf.d/50unattended-upgrades: which origins are allowed, packages to blacklist, and whether to reboot automatically (Unattended-Upgrade::Automatic-Reboot, off by default). Logs land in /var/log/unattended-upgrades/. If apt ever reports “Could not get lock /var/lib/dpkg/lock-frontend”, unattended-upgrades is usually running: wait a few minutes. Never delete lock files; if a previous run was interrupted, sudo dpkg --configure -a finishes it.
Restarts and reboots after updates
Updating a library does not change processes that already loaded the old version, and a new kernel only runs after a reboot. Ubuntu tells you both:
$ cat /var/run/reboot-required
*** System restart required ***
$ cat /var/run/reboot-required.pkgs
linux-image-7.0.0-17-generic
$ sudo needrestart -r l
needrestart (installed on Ubuntu Server) checks which services still run outdated code; -r l only lists them. Plan kernel reboots like deployments: one server at a time behind the load balancer, so orbit-web-01 and orbit-web-02 are never down together.
Red Hat: dnf and rpm
On orbit-reports (Rocky Linux 10) the ideas are identical and the words change:
| Task | Ubuntu | Rocky, RHEL, Fedora |
|---|---|---|
| Refresh and list updates | apt update then apt list --upgradable | dnf check-update (refreshes on its own) |
| Upgrade everything | apt upgrade | dnf upgrade |
| Install / remove | apt install / apt remove | dnf install / dnf remove |
| Search / details | apt search / apt show | dnf search / dnf info |
| Which package owns a file | dpkg -S /path | rpm -qf /path or dnf provides /path |
| Files in a package | dpkg -L pkg | rpm -ql pkg or dnf repoquery -l pkg |
| List installed | dpkg -l | rpm -qa or dnf list --installed |
| Hold a version | apt-mark hold | dnf versionlock add (versionlock plugin) |
| Undo the last change | not built in | dnf history then dnf history undo ID |
| Automatic updates | unattended-upgrades | dnf-automatic with its systemd timer |
| Reboot needed? | /var/run/reboot-required | dnf needs-restarting -r |
dnf history undo is a genuine advantage: every transaction gets an ID, and you can roll it back. yum still exists on RHEL as a compatibility name for dnf. Repositories are .repo files in /etc/yum.repos.d/, and EPEL adds many community packages (sudo dnf install epel-release).
Alpine: apk in containers
Alpine’s apk is tiny and fast, and you meet it mostly in Dockerfiles:
FROM alpine:3.23
RUN apk add --no-cache nginx curl
--no-cache fetches the index, installs and keeps no index files in the image, so there is no separate apk update and no cleanup step. Other everyday commands: apk del, apk search, apk info -L nginx (files in a package) and apk add --virtual .build-deps gcc musl-dev to group build tools you delete later with apk del .build-deps. The Ubuntu equivalent in a Dockerfile is apt-get update && apt-get install -y --no-install-recommends ... && rm -rf /var/lib/apt/lists/* in a single RUN.
Snap, Flatpak and AppImage
These formats bundle an application with its dependencies so one build runs on many distributions. Snap (Canonical) installs with sudo snap install name, updates itself in the background and runs sandboxed; Ubuntu delivers some tools this way, LXD for example. Flatpak targets desktop apps and is the norm on Fedora desktops. An AppImage is a single executable file you chmod +x and run, with no central updates. On servers, prefer distribution packages or vendor repositories: they are patched by the same process as the rest of the system and are what configuration tools expect. If you do use a snap, sudo snap refresh --hold=24h name postpones its automatic updates.
Install nginx for Orbit
Orbit’s API listens on 127.0.0.1:3000, and nginx will sit in front of it on ports 80 and 443. On orbit-lab:
$ sudo apt update
$ sudo apt install -y nginx
$ systemctl is-active nginx
active
$ curl -sI http://localhost | head -2
HTTP/1.1 200 OK
Server: nginx/1.28.0 (Ubuntu)
Debian packages start and enable services right after installing them, so nginx is already serving its welcome page. dpkg -L nginx-common | grep sites-available shows where its site configuration lives. Pointing nginx at the API is a configuration task, not a packaging one; what matters here is that you know which package owns which file and which version is running.
Practice lab
Leo asks you to prepare orbit-lab the way production servers are set up:
- Refresh the indexes, list what can be upgraded and apply the upgrades.
- Install
nginx,jqandncdu, then find which package owns/usr/sbin/nginxand how many filesjqinstalled. - Put
nginxon hold, confirm it withapt-mark showhold, then release it. - Check that unattended-upgrades is enabled and whether the machine needs a reboot.
- Remove
ncduwithpurgeand clean up unused dependencies.
Show a solution
Run sudo apt update, apt list --upgradable and sudo apt upgrade. Install with sudo apt install -y nginx jq ncdu; dpkg -S /usr/sbin/nginx answers nginx, and dpkg -L jq | wc -l counts its files (directories included). Hold with sudo apt-mark hold nginx, check with apt-mark showhold, release with sudo apt-mark unhold nginx. cat /etc/apt/apt.conf.d/20auto-upgrades should show both settings as "1", and ls /var/run/reboot-required either prints the file (reboot due) or “No such file or directory”. Finish with sudo apt purge -y ncdu and sudo apt autoremove -y.
Exercise
A CI job builds an image FROM ubuntu:26.04 and runs apt-get install -y nginx. It fails with “Unable to locate package nginx”. What is missing?
Show answer
Answer: B. Official images remove /var/lib/apt/lists to stay small, so apt knows no packages until you run apt-get update, ideally in the same RUN as the install.
Exercise
orbit-db-01 must stay on its current PostgreSQL package until the team plans an upgrade, while everything else keeps receiving updates. What do you do?
Show answer
Answer: D. A hold freezes only the named packages; the rest of the system still gets security fixes. Stopping upgrades or removing the security pocket leaves the whole server unpatched.
Exercise
A monitoring vendor’s install guide says to run curl -fsSL https://vendor.example/key | sudo apt-key add -. What is the safer equivalent on Ubuntu 26.04?
Show answer
Answer: B. Signed-By scopes the vendor key to that one source. apt-key trusted keys globally and is gone from current releases; trusted=yes disables verification entirely.
Key takeaways
- Packages come from signed repositories; the package manager resolves dependencies and tracks every file.
apt updaterefreshes indexes,apt upgradeapplies updates,full-upgrademay also remove packages.- Use
dpkg -l,-Land-Sto answer what is installed, what it contains and who owns a file. - Add vendor repositories with a key in
/etc/apt/keyringsandSigned-By, never withapt-keyortrusted=yes. - Keep unattended security updates on, and watch
/var/run/reboot-requiredandneedrestart. dnfandapkdo the same jobs with different words;dnf history undois worth knowing.
FAQ
What is the difference between apt and apt-get?
Both use the same engine. apt is the friendly front end for people: progress bars, colours and combined commands like apt list. apt-get and apt-cache keep a stable output and behaviour, so scripts, Dockerfiles and configuration tools should use them. At the keyboard, use apt.
What does “Unable to locate package” mean?
apt’s index does not contain that name. Usually you have not run sudo apt update yet (always the case in fresh containers), the name is spelled differently on this distribution, or it lives in a component or repository that is not enabled, such as universe or a vendor repository. apt search --names-only helps find the right name.
How do I fix “Could not get lock /var/lib/dpkg/lock-frontend”?
Another package process is running, most often unattended-upgrades right after boot. Wait for it, and check with ps aux | grep -E 'apt|dpkg'. Do not delete the lock files: two package managers writing at once can corrupt the database. If a run was killed halfway, sudo dpkg --configure -a completes it.
Is it safe to run apt upgrade on production servers?
Within an LTS release, updates are bug and security fixes chosen to avoid breaking changes, so yes, with the usual care: test on staging first, upgrade one server at a time, and watch the services afterwards. Security updates are best automated with unattended-upgrades. Major version jumps (do-release-upgrade) are a different project and need a plan. ??? What is the difference between dnf, yum and rpm? rpm installs and queries individual package files without resolving dependencies, much like dpkg. dnf is the high-level tool that talks to repositories and resolves dependencies, like apt. yum was its predecessor; on current RHEL, Rocky and Alma the yum command still works but simply runs dnf.