Packages and updates
Install, remove and update software with apt, find which package owns a file, and handle reboots and automatic updates.
The idea
Software comes as packages from repositories (download servers). apt downloads them, resolves dependencies and keeps track of what is installed. apt update only refreshes the list of available versions; apt upgrade actually installs them.
apt cheat sheet
| What | Command |
|---|---|
| Refresh package lists | sudo apt update |
| Install all updates | sudo apt upgrade |
| Updates incl. new dependencies / removals | sudo apt full-upgrade |
| Install | sudo apt install nginx |
| Remove (keep config) | sudo apt remove nginx |
| Remove incl. config | sudo apt purge nginx |
| Remove unused dependencies | sudo apt autoremove |
| Search | apt search keyword |
| Details / version | apt show nginx |
| What can be updated? | apt list --upgradable |
| Is it installed? | apt list --installed | grep nginx |
| Which files did a package install? | dpkg -L nginx |
| Which package owns this file? | dpkg -S /usr/sbin/nginx |
Install a downloaded .deb | sudo apt install ./file.deb |
| Keep a package at its version | sudo apt-mark hold PACKAGE (unhold to undo) |
Reboot needed?
After kernel or library updates:
cat /var/run/reboot-required.pkgs 2>/dev/null || echo "no reboot needed"
Automatic security updates
Ubuntu Server installs unattended-upgrades by default. It installs security updates daily, but does not reboot unless you allow it.
systemctl status unattended-upgrades
less /var/log/unattended-upgrades/unattended-upgrades.log
Settings are in /etc/apt/apt.conf.d/50unattended-upgrades (e.g. Automatic-Reboot).
Snaps
Some software (e.g. lxd) comes as a snap: a self-contained package that updates itself.
| What | Command |
|---|---|
| List snaps | snap list |
| Install / remove | sudo snap install NAME / sudo snap remove NAME |
| Update now | sudo snap refresh |
Upgrade to the next Ubuntu release
sudo apt update && sudo apt full-upgrade
sudo do-release-upgrade
Run it inside tmux (see Terminal shortcuts) and take a snapshot first. By default you are only offered the next LTS release once its first point release is out.