To update and patch an Ubuntu server safely, run sudo apt update to refresh package lists, review the changes with apt list --upgradable, take a snapshot or backup, then run sudo apt upgrade and reboot if the system says a restart is required. Turn on unattended security updates so critical fixes install automatically.
Unpatched servers are the easiest target for attackers, but careless upgrades can also break a production site. This guide covers the difference between the apt commands, a safe upgrade routine, handling reboots and held packages, and automatic security patching on Ubuntu LTS.
The two commands do different jobs and are used together:
| Command | What it does |
|---|---|
sudo apt update | Downloads the latest package lists from the repositories. Installs nothing. |
sudo apt upgrade | Installs newer versions of installed packages. Never removes packages. |
sudo apt full-upgrade | Upgrades and may remove or install packages to resolve dependency changes. |
sudo apt autoremove | Removes packages that were installed as dependencies and are no longer needed. |
Running upgrade without update first installs nothing new, because apt works from its cached lists. The older apt-get command still works and is common in scripts, but apt is the friendlier interface for manual use.
df -h. A full disk in the middle of an upgrade can leave packages half-installed.Apt lists the packages and asks for confirmation. During the run, a configuration prompt may ask whether to keep your version of a file or install the maintainer's version. Keep your local version unless you know you need the new one, and compare the differences later.
When it finishes, check whether the machine needs a reboot, which is needed after kernel and some library updates:
If the file exists, plan a reboot with sudo reboot. Services such as a web server can often be restarted without a full reboot, but a kernel update only takes effect after the reboot. The needrestart tool, installed by default on recent Ubuntu server releases, lists services that still use old libraries and offers to restart them.
If a package must stay at a known version, for example a database server in production, mark it as held:
Held packages skip apt upgrade, but they stop receiving security fixes, so review holds regularly.
Ubuntu includes the unattended-upgrades package, which installs security updates in the background. Install and enable it:
The settings live in /etc/apt/apt.conf.d/50unattended-upgrades. By default it applies only the security pocket, which is the safe choice, because it avoids feature changes. You can allow automatic reboots at a quiet hour:
Test the configuration without changing anything, and read the log:
Only enable automatic reboots when the service tolerates a short outage or runs behind a load balancer.
Package patching keeps you on the same Ubuntu release. Moving to a new release, such as from one LTS to the next, uses do-release-upgrade and is a bigger change that deserves a snapshot, a maintenance window and a test run first. Each LTS release gets standard security maintenance for five years, so you do not need to hurry, but you must move before support ends.
Use apt upgrade for routine patching. Use apt full-upgrade when apt reports packages kept back because a dependency change is required.
No. Reboot after kernel updates or when /var/run/reboot-required exists. Other updates usually only need a service restart.
Security-only automatic updates are widely used and low risk. Keep backups and monitoring, and test large changes on staging.
Run sudo dpkg --configure -a followed by sudo apt -f install to finish or repair half-configured packages.
Patch Ubuntu by running apt update, reviewing apt list --upgradable, taking a snapshot, then apt upgrade, and reboot when the reboot-required file appears. Hold only packages you must, enable unattended-upgrades for security fixes, and treat release upgrades as a separate planned task.