How to Update Ubuntu Server from the Terminal

· 0x.cloud Team

How to Update Ubuntu Server from the Terminal

Here is how to update Ubuntu Server in two commands: sudo apt update refreshes the package lists, and sudo apt upgrade installs the newer versions. Then remove leftovers with sudo apt autoremove and reboot if the system asks for it. Below is the full routine for Ubuntu 24.04 (and Debian 12), the difference between upgrade and full-upgrade, release upgrades, and fixes for the usual errors.

Before You Update: Have a Way Back

Routine package updates rarely break anything, but kernel updates, database upgrades and release upgrades can. Take a snapshot before a big update so you can roll back in minutes. On 0x.cloud a snapshot costs $0.99/month; see VPS snapshots.

Make sure you have at least 1–2 GB of free disk space:

df -h /

Low on space? Clean up first with how to check disk space on Linux.

How to Update Ubuntu Server: Step-by-Step Commands

# 1. refresh package lists from the repositories
sudo apt update

# 2. preview what will change (optional)
apt list --upgradable

# 3. install newer versions of installed packages
sudo apt upgrade

# 4. install updates that need new dependencies or package removals
sudo apt full-upgrade

# 5. remove packages that are no longer needed (old kernels, orphaned deps)
sudo apt autoremove --purge

# 6. check whether a reboot is required
[ -f /var/run/reboot-required ] && cat /var/run/reboot-required.pkgs

If step 6 prints packages (usually linux-image-...), reboot:

sudo reboot

Reconnect after a minute and confirm the running kernel with uname -r. If you are logged in as root, you can drop sudo.

The everyday one-liner:

sudo apt update && sudo apt upgrade -y && sudo apt autoremove --purge -y

-y answers "yes" to the confirmation prompt. Commands follow the official Ubuntu Server docs.

apt Commands Compared

Command What it does When to use it
apt update downloads package lists, installs nothing before every install or upgrade
apt upgrade upgrades packages without removing any routine updates
apt full-upgrade upgrades and may add or remove packages to resolve dependencies new kernels, bigger updates
apt-get dist-upgrade same as full-upgrade, older name scripts and older guides
apt autoremove removes unused dependencies after updates
do-release-upgrade moves to a new Ubuntu release for example 22.04 to 24.04

Use apt-get in scripts and cron jobs: apt output is meant for humans and may change.

Update Ubuntu Server from the Command Line Without Prompts

After library updates, needrestart may ask "Which services should be restarted?". For unattended runs (scripts, CI, or an AI agent doing maintenance), use non-interactive mode:

# upgrade without prompts and keep your current config files
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
  -o Dpkg::Options::="--force-confold" upgrade

--force-confold keeps your existing config files when a package ships a new version.

Automatic Security Updates

According to the Ubuntu docs, Ubuntu Server enables automatic security updates by default and runs unattended-upgrades once a day. It does not reboot by default. Run systemctl status unattended-upgrades to confirm it is active on your server. To tune it and schedule nightly reboots, read unattended upgrades on Ubuntu.

How to Upgrade Ubuntu Server 22.04 to 24.04

  1. Take a snapshot or backup.
  2. Fully update the current release and reboot if /var/run/reboot-required exists:
    sudo apt update && sudo apt full-upgrade
    
  3. Start the release upgrade:
    sudo do-release-upgrade
    
  4. Answer the prompts. When asked about replacing a modified config file (such as sshd_config), keeping your current version is the default.
  5. After the final reboot, check with lsb_release -a.

An upgrade to the next LTS is offered only after its first point release (for example 24.04.1).

Heads-up for 24.04 servers. On September 29, 2026, Canonical enabled upgrades from 24.04 to 26.04.1 LTS, so sudo do-release-upgrade on Ubuntu 24.04 now offers 26.04. If you only want package updates, skip that command: apt update and apt upgrade keep you on 24.04, which gets security updates until 2029. Move to 26.04 on purpose, after a snapshot and after checking your software supports it. Third-party repositories and PPAs are disabled during the upgrade, so re-enable them afterward. Run do-release-upgrade inside tmux so a dropped SSH connection does not interrupt it.

For a disposable server, a clean install is faster: OS reinstalls on 0x.cloud are free and Ubuntu 24.04 is one of the images. See how to reinstall the OS.

Common Errors and Fixes

Error Cause Fix
Could not get lock /var/lib/dpkg/lock-frontend apt or unattended-upgrades is already running wait 5–10 minutes; check ps aux | grep -i apt; never delete lock files by hand
dpkg was interrupted a previous upgrade was cut off sudo dpkg --configure -a, then sudo apt -f install
No space left on device the disk is full sudo apt clean && sudo apt autoremove --purge, then find large files
The following packages have been kept back phased updates or new dependencies wait a couple of days or run sudo apt full-upgrade
Temporary failure resolving DNS is broken check ping -c 3 archive.ubuntu.com and /etc/resolv.conf
Server does not come back after reboot bad kernel or config change restore the snapshot or reinstall the OS

Let an AI Agent Handle Routine Updates

Routine patching is a good job for Claude Code or Codex:

Prompt for an AI agent

Connect to my server over SSH or through the 0x.cloud MCP. Check free space with df -h /, then update without prompts: DEBIAN_FRONTEND=noninteractive apt-get update and apt-get -y -o Dpkg::Options::="--force-confold" upgrade, then apt-get -y autoremove --purge. Do not run do-release-upgrade. Show me which packages changed and whether /var/run/reboot-required exists. Reboot only after I confirm.

Need a throwaway box to test updates first? On 0x.cloud, Ubuntu 24.04 is one of the images, reinstalls cost $0, and s1-2 on hourly billing is about $0.054725 an hour. See all plans on the pricing page.

FAQ

What is the difference between apt update and apt upgrade? apt update only refreshes the package lists from the repositories and installs nothing. apt upgrade installs newer versions of the packages you already have. Always run update first.

How often should I update my Ubuntu server? By default, Ubuntu Server installs security updates on its own once a day through unattended-upgrades (check with systemctl status unattended-upgrades). Run a full manual update every one to two weeks and before installing new software.

Do I need to reboot after updating? Only if the file /var/run/reboot-required exists, usually after a kernel or core library update. Other updates take effect without a reboot.

How do I upgrade Ubuntu 22.04 to 24.04 on a server? Take a snapshot or backup, fully update the current release, reboot, then run sudo do-release-upgrade. The process is interactive and usually takes 15–40 minutes. Note that since September 29, 2026, the same command on 24.04 offers an upgrade to 26.04.

Do these commands work on Debian 12? Yes. apt update, upgrade, full-upgrade and autoremove behave the same on Debian. Only release upgrades differ: on Debian you switch the repository codename.