
# 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](https://0x.cloud/kb/servers/vps-snapshot).

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

```bash
df -h /
```

Low on space? Clean up first with [how to check disk space on Linux](https://0x.cloud/kb/servers/disk-space-linux).

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

```bash
# 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:

```bash
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:

```bash
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](https://ubuntu.com/server/docs/how-to/software/package-management/).

## 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:

```bash
# 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](https://ubuntu.com/server/docs/how-to/software/automatic-updates/), 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](https://0x.cloud/kb/security/unattended-upgrades).

## 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:
   ```bash
   sudo apt update && sudo apt full-upgrade
   ```
3. Start the release upgrade:
   ```bash
   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](https://discourse.ubuntu.com/t/upgrades-from-ubuntu-24-04-lts-to-ubuntu-26-04-1-lts-now-enabled/88502), 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](https://0x.cloud/kb/servers/reinstall-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:


```text
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](https://0x.cloud/pricing).


[Create server: s1-2, $7.99/mo](https://0x.cloud/cabinet/create?plan=s1-2)


## 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.
