> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Update an Ubuntu, Debian or AlmaLinux Server

> How to update an Ubuntu, Debian or AlmaLinux server: run apt update and apt upgrade, or dnf upgrade on AlmaLinux and Rocky, then check whether a reboot is needed.

To update an Ubuntu or Debian server, run `sudo apt update` to refresh the package list, then `sudo apt upgrade` to install the updates. On AlmaLinux or Rocky Linux, run `sudo dnf upgrade`. Afterwards, check whether a reboot is needed: Ubuntu and Debian create `/var/run/reboot-required`, and on AlmaLinux and Rocky `sudo dnf needs-restarting -r` tells you.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 to 15 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | sudo or root access |

## Before you start

* [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md) as a user with sudo rights. If you are logged in as `root`, leave out `sudo`.
* On a production server, take a [backup or snapshot](https://help.freakhosting.com/portals/vps-panel/how-to-schedule-and-restore-backups.md) first. Updates rarely break things, but a kernel or database update can.
* If you might lose SSH, have the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md) ready.

## How to update Ubuntu and Debian

**1. Refresh the package list**

```bash theme={null}
sudo apt update
```

This downloads the latest list of packages. It installs nothing. The last line tells you how many packages can be upgraded.

**2. See what will change (optional)**

```bash theme={null}
apt list --upgradable
```

**3. Install the updates**

```bash theme={null}
sudo apt upgrade
```

Type `y` and press `Enter` to confirm. Add `-y` to skip the question in scripts.

**4. Remove packages that are no longer needed**

```bash theme={null}
sudo apt autoremove
```

This removes old kernels and dependencies that nothing uses any more.

### apt upgrade or apt full-upgrade?

`apt upgrade` never removes a package. If an update needs to remove or replace something, that package is "kept back". `apt full-upgrade` (the same as `apt-get dist-upgrade`) also installs new dependencies and removes conflicting packages, which is what new kernels sometimes need.

```bash theme={null}
sudo apt full-upgrade
```

Read the list of packages it wants to remove before you type `y`. `full-upgrade` updates within your current release; it does not move you to a new Ubuntu or Debian version. For that, see [upgrade Ubuntu to a new release](https://help.freakhosting.com/portals/other/how-to-upgrade-ubuntu-to-a-new-release.md) or [upgrade Debian 12 to 13](https://help.freakhosting.com/portals/other/how-to-upgrade-debian-12-to-debian-13.md).

> [!NOTE]
>
> If a config file you changed also changed in the new package, apt asks what to do. The safe answer is the default, **keep your currently-installed version** (`N`), then compare the files later.

## How to update AlmaLinux and Rocky Linux

**1. Check for updates (optional)**

```bash theme={null}
sudo dnf check-update
```

This lists packages with available updates.

**2. Install all updates**

```bash theme={null}
sudo dnf upgrade
```

`dnf upgrade` refreshes the repository metadata itself when it is out of date. Add `--refresh` to force a fresh download. Confirm with `y`.

**3. Remove unneeded packages**

```bash theme={null}
sudo dnf autoremove
```

To install only security updates, run:

```bash theme={null}
sudo dnf upgrade --security
```

`dnf` always installs a new kernel next to the old one rather than replacing it, so you can boot the previous kernel if the new one causes a problem.

## How to update a single package

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt update
> sudo apt install --only-upgrade nginx
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf upgrade nginx
> ```

## How to check if a reboot is needed

Kernel, `glibc` and `systemd` updates only take full effect after a reboot.

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> cat /var/run/reboot-required
> cat /var/run/reboot-required.pkgs
> ```
>
> If the file exists you see `*** System restart required ***`, and the `.pkgs` file lists which packages asked for it. If it does not exist, no reboot is needed.

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf needs-restarting -r
> ```
>
> It reports whether a reboot is required and exits with code `1` if it is, `0` if not. `sudo dnf needs-restarting -s` lists services that only need a restart.

Reboot with:

```bash theme={null}
sudo reboot
```

Your SSH session closes. Wait a minute, then reconnect.

## How to check it worked

Run the update command again. When everything is current you see:

> [tab] Ubuntu / Debian
>
> ```text theme={null}
> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
> ```

> [tab] AlmaLinux / Rocky
>
> ```text theme={null}
> Dependencies resolved.
> Nothing to do.
> Complete!
> ```

## Frequently asked questions

### How often should I update my server?

Install security updates at least weekly, or turn on [automatic security updates](https://help.freakhosting.com/portals/other/how-to-enable-automatic-security-updates.md) so they install daily.

### What does "The following packages have been kept back" mean?

The update needs to install or remove other packages, which `apt upgrade` doesn't do, or it is a phased update that Ubuntu is rolling out gradually. Run `sudo apt full-upgrade` to install the held packages, or wait a few days for phased updates.

### Is `apt-get` different from `apt`?

`apt` is the friendlier command for people at the terminal. `apt-get` gives the same results with a stable output format, so use `apt-get` in scripts.

### I get "Could not get lock /var/lib/dpkg/lock". What now?

Another update is running, often the automatic one. Wait a few minutes and try again. See [how to fix the dpkg lock error](https://help.freakhosting.com/portals/other/how-to-fix-could-not-get-lock-var-lib-dpkg-lock.md).

### Does `yum` still work on AlmaLinux and Rocky?

Yes. `yum` is a link to `dnf`, so `sudo yum update` runs the same update. New guides use `dnf`.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Automatic security updates](https://help.freakhosting.com/portals/other/how-to-enable-automatic-security-updates.md)
>
> unattended-upgrades and dnf-automatic.

> [card] [Upgrade Ubuntu to a new release](https://help.freakhosting.com/portals/other/how-to-upgrade-ubuntu-to-a-new-release.md)
>
> Move from 22.04 to 24.04.

> [card] [Fix apt and dnf repository errors](https://help.freakhosting.com/portals/other/how-to-fix-apt-and-dnf-repository-errors.md)
>
> When updates fail.

> [card] [Back up your VPS](https://help.freakhosting.com/portals/vps-panel/how-to-schedule-and-restore-backups.md)
>
> Snapshot before big changes.

***

> [!NOTE]
>
> **Checked against the official [Red Hat Enterprise Linux 9 DNF documentation](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_software_with_the_dnf_tool/assembly_updating-rhel-9-content_managing-software-with-the-dnf-tool), the [DNF needs-restarting plugin docs](https://dnf-plugins-core.readthedocs.io/en/latest/needs_restarting.html) and the [Ubuntu Server documentation](https://documentation.ubuntu.com/server/)** on 4 November 2026; apt commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.