How to Update Ubuntu OS from the Command Line (apt and LTS)
- November 5, 2026
- 9:00 am
- By Adrien Roche
- Tutorials

How to update Ubuntu OS from the terminal: the everyday commands
Every Ubuntu flavour, Desktop, Server or the cloud image on a VPS, is updated through APT, which splits the job in two: learn what the repositories offer, then install it. A routine update is therefore two commands:
sudo apt update
sudo apt upgradeapt update downloads the package lists from the repositories declared in /etc/apt/sources.list and /etc/apt/sources.list.d/ (on 24.04 the main entries live in the deb822 file /etc/apt/sources.list.d/ubuntu.sources). It installs nothing and ends with N packages can be upgraded. Run 'apt list --upgradable' to see them. apt upgrade then installs the newer versions of the packages already present, shows the download size, and waits for a Y; -y skips the prompt.
apt list --upgradable
sudo apt upgrade -y
sudo apt autoremove
[ -f /var/run/reboot-required ] && cat /var/run/reboot-requiredThe last line is the check most people skip: if the file exists, a kernel or core library was replaced and a reboot is needed before the update is in effect. In scripts, prefer apt-get (the stable interface) with DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confold" upgrade to keep your edited configuration files. APT does not touch snaps; sudo snap refresh does.
apt update vs upgrade vs full-upgrade vs dist-upgrade
Four verbs that look interchangeable and are not. None of them moves you to a newer Ubuntu release; that is a separate tool.
| Command | What it does | Adds packages | Removes packages |
|---|---|---|---|
apt update | Refreshes the package index only | No | No |
apt upgrade | Upgrades installed packages | New dependencies only | Never |
apt-get upgrade | Same, but adds nothing either | No | Never |
apt full-upgrade | Upgrades the whole system, removing packages when unavoidable | Yes | If required |
apt-get dist-upgrade | The apt-get name for full-upgrade (apt dist-upgrade is an alias) | Yes | If required |
apt autoremove | Deletes unneeded auto-installed dependencies | No | Yes |
apt upgrade is the safe daily choice: it never removes anything. When an upgrade would require a removal (a library renamed, a package split in two), it lists the package as kept back instead. apt full-upgrade is the same operation with permission to remove; it prints the removal list before asking; read it carefully on a production server. dist-upgrade is the most misleading name in APT: it is simply full-upgrade under apt-get and will not take you from 22.04 to 24.04.
apt autoremove deletes packages installed automatically as dependencies (apt-mark showauto lists them) once nothing needs them. On Ubuntu that includes old kernels, with the running one and the newest installed one always protected; --purge also drops their configuration files. All of this is identical on Debian, worth knowing if you are still weighing Debian against Ubuntu for a VPS: same tooling, different release cadence and support windows.
Held packages, "kept back" and phased updates
Sooner or later apt upgrade ends with The following packages have been kept back:. Three causes, three fixes.
1. The package is on hold
A hold pins a package at its current version until you lift it, typically for a kernel or database server at a version you have tested.
apt-mark showhold
sudo apt-mark hold nginx
sudo apt-mark unhold nginx2. The upgrade needs to add or remove packages
apt upgrade never removes and apt-get upgrade never adds, so a package whose new version drops an old dependency is kept back. Run sudo apt full-upgrade, read the proposed removals, confirm if they make sense.
3. The update is phased
Since Ubuntu 21.04, updates from the -updates pocket roll out gradually, so a bad update can be pulled before it reaches everyone. APT reports them as The following upgrades have been deferred due to phasing. Nothing is wrong; they arrive within days, and the -security pocket is not phased. To pull one now:
sudo apt -o APT::Get::Always-Include-Phased-Updates=true upgradeKernel updates, reboot-required and restarting services
On a KVM VPS the guest boots its own kernel, like a physical machine. A new linux-image-* package lands in /boot and GRUB is updated, but the running kernel stays in memory until the next reboot. (On OpenVZ or LXC containers the kernel belongs to the host, so a guest kernel upgrade changes nothing.) To compare running and installed:
uname -r
ls /boot/vmlinuz-* | sort -V | tail -n 1
cat /var/run/reboot-required.pkgs/var/run/reboot-required and reboot-required.pkgs are written by update-notifier-common hooks when a kernel, the C library or a similarly fundamental package is upgraded; the .pkgs file names the culprits. Ubuntu Server 22.04 and later also ship needrestart, which after every APT run lists services still using replaced libraries and offers to restart them. In scripts it can block on that dialog: run sudo needrestart -r a, or set $nrconf{restart} = 'a'; in /etc/needrestart/needrestart.conf.
When the reboot is due, sudo systemctl reboot is enough; the Linux reboot and shutdown commands guide covers scheduling it and warning logged-in users. Canonical Livepatch (Ubuntu Pro, free for up to five machines) applies some kernel security fixes without rebooting, but only a subset, so periodic reboots remain part of the routine.
Automatic security patches with unattended-upgrades
Ubuntu Server and the cloud images install unattended-upgrades by default, set to install security updates only, driven by the apt-daily.timer and apt-daily-upgrade.timer systemd timers. To confirm it is on, enable it, or preview what it would do:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
sudo unattended-upgrade --dry-run --debug
systemctl list-timers 'apt-daily*'
tail -n 30 /var/log/unattended-upgrades/unattended-upgrades.logThe on/off switch is /etc/apt/apt.conf.d/20auto-upgrades; the policy is /etc/apt/apt.conf.d/50unattended-upgrades, where in Allowed-Origins the "${distro_id}:${distro_codename}-security" line is active and the -updates line is commented out. Uncomment the latter only if you want every stable update applied automatically. Two more options matter on a server:
Unattended-Upgrade::Remove-Unused-Dependencies "true";runs the equivalent ofautoremoveso old kernels do not fill/boot.Unattended-Upgrade::Automatic-Reboot "true";withAutomatic-Reboot-Time "03:00";reboots when required. Enable it only if the workload tolerates an unplanned restart.
While it runs, unattended-upgrades holds the dpkg lock, the usual origin of the lock error covered in the last section.
Upgrade to the next LTS: do-release-upgrade from 22.04 to 24.04 on a VPS
apt upgrade keeps you on the same release forever. Each LTS gets five years of standard updates (22.04 until April 2027, 24.04 until April 2029). Moving on is the job of do-release-upgrade. Three rules: an LTS is offered the next LTS only once its first point release (24.04.1) exists, you cannot skip a release (20.04 goes to 22.04, then 24.04), and /etc/update-manager/release-upgrades must say Prompt=lts, the LTS default. The same steps apply from 24.04 to 26.04 LTS once the upgrader offers it.
1. Snapshot, then check the starting point
Take a snapshot from your provider's panel first; an upgrade that dies halfway is far easier to roll back than to repair. Confirm what you run with lsb_release -a (see how to find your OS version from the command line) and check df -h / /boot: the upgrader refuses to start without a few gigabytes free.
2. Bring the current release fully up to date
sudo apt update && sudo apt full-upgrade -y
sudo apt autoremove --purge -y
[ -f /var/run/reboot-required ] && sudo systemctl rebootThe upgrader refuses to run with pending or broken packages.
3. Protect the SSH session
Run it inside tmux so that a dropped connection does not kill the upgrade: sudo apt install tmux, tmux new -s upgrade, and after a disconnect tmux attach -t upgrade. The upgrader also detects SSH, warns against it, and starts a second sshd on port 1022 as an emergency path; if UFW is active, sudo ufw allow 1022/tcp first. On a VPS, SSH is usually all you have; the snapshot and the panel console are the fallback.
4. Run the upgrader
sudo do-release-upgrade -c
sudo do-release-upgrade-c only reports which release would be offered. The real run disables third-party repositories in /etc/apt/sources.list.d/, rewrites the Ubuntu sources from jammy to noble, downloads everything, then asks whether to keep locally modified configuration files (keep anything you edited), remove obsolete packages, and finally reboot. Do not interrupt it once packages are being installed.
5. After the reboot
lsb_release -a
uname -r
sudo apt update && sudo apt full-upgrade
sudo apt autoremove --purgeRe-enable only the PPAs that publish for noble, close port 1022, test your services, then delete the snapshot.
Fixing common apt errors
Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr). Another APT process is running, usually unattended-upgrades shortly after boot. Recent apt prints Waiting for cache lock and retries for up to two minutes; give apt-get the same patience with -o DPkg::Lock::Timeout=600. Delete a lock file only when sudo lsof /var/lib/dpkg/lock-frontend shows no holder, after a crash for instance, then run sudo dpkg --configure -a.
dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'. A previous run was killed mid-way; the suggested command finishes configuring the half-installed packages. Unmet dependencies. Try 'apt --fix-broken install'. Usually the aftermath of a failed install or a hand-downloaded .deb; run it, then retry, and if one package keeps failing, read the error printed above the summary.
sudo dpkg --configure -a
sudo apt --fix-broken install
sudo apt clean && sudo rm -rf /var/lib/apt/lists/* && sudo apt updateErrors during apt update are repository problems. NO_PUBKEY: a third-party signing key is missing, re-import it as the vendor documents. The repository does not have a Release file: a dead PPA, delete its file from /etc/apt/sources.list.d/. A wall of 404 Not Found from the Ubuntu mirrors: the release is end-of-life and moved to old-releases.ubuntu.com; the real fix is a release upgrade. Release file is not valid yet: the clock is wrong, check timedatectl. Hash Sum mismatch: stale or corrupted local lists, which the third line above wipes and re-downloads.
All of this assumes a machine where you hold root and can afford to reboot and roll back. An Ubuntu VPS from rdp.monster is that machine: KVM, full root access, dedicated CPU and RAM, unlimited (fair-use) bandwidth, no KYC, crypto or fiat payment, from $8.99 per month, ready about 10 seconds after payment confirms. Run the two-command update first thing after you log in.
Frequently Asked Questions
Do I need to reboot Ubuntu after every update?
/var/run/reboot-required, and /var/run/reboot-required.pkgs names the packages responsible. On Ubuntu Server, needrestart also lists services still using outdated libraries so you can restart those instead of the whole machine when the kernel is unchanged.Can I upgrade Ubuntu 20.04 directly to 24.04?
do-release-upgrade only knows how to move to the next release, so a 20.04 system must first become 22.04, be rebooted and fully updated, and then be upgraded again to 24.04. Each hop takes a while and each deserves its own snapshot. On a server with little custom configuration it is often faster and cleaner to deploy a fresh 24.04 VPS, migrate the data and services, and retire the old machine, rather than carrying two releases’ worth of upgrade history and leftover packages forward.How often should I update an Ubuntu server?
unattended-upgrades configuration does every day. The rest, meaning the -updates pocket with bug fixes and phased rollouts, is best applied by hand with sudo apt update && sudo apt upgrade on a cadence you can supervise, weekly for exposed services and monthly for quiet machines. Whatever the schedule, watch for /var/run/reboot-required: a kernel patched two months ago but never booted protects nothing.What is the difference between apt and apt-get?
apt combines the most used commands of apt-get and apt-cache, adds a progress bar, colour and apt list --upgradable, and its upgrade may install new dependencies where apt-get upgrade will not. Its output format is not guaranteed stable, which is why it warns when used in scripts. In cron jobs, cloud-init or Ansible-style automation, call apt-get with -y and DEBIAN_FRONTEND=noninteractive; for interactive use, apt is the better tool.Adrien Roche, Infrastructure & Hosting Editor
Systems engineer with 10+ years operating Windows Server and Linux fleets. Adrien runs the rdp.monster infrastructure documentation and writes our guides on RDP, VPS hosting, server administration, networking and privacy tooling.
Related Posts




