What this is
This guide explains how to update an Ubuntu or Debian server using apt (the package manager).
What it is for
- Install security patches and bug fixes
- Keep your VPS stable and supported
- Reduce risk of vulnerabilities
Prerequisites
- SSH access to your VPS
- A user with
sudoprivileges (or root) - Recommended: a backup/snapshot before updating
Step-by-step (extremely detailed)
Step 1) Confirm the OS is Ubuntu/Debian
cat /etc/os-release
What it does: Shows your distribution and version.
Why it is needed: These commands are specifically for APT-based systems.
Expected output: Lines like NAME="Ubuntu" or NAME="Debian".
Step 2) Update the package list
sudo apt update
What it does: Downloads the latest package index from your repositories.
Why it is needed: Without this, your server may not “see” the newest updates.
Expected output: You will see repository lines and a final message like Reading package lists... Done.
Warning: If you see repository errors, stop and fix them before upgrading.
Step 3) See what would be upgraded (optional but recommended)
apt list --upgradable
What it does: Lists packages with available upgrades.
Expected output: A list of packages (or nothing if up to date).
Step 4) Install upgrades
sudo apt upgrade -y
What it does: Upgrades installed packages to newer versions.
Why it is needed: This is the main step that applies security patches.
Expected output: Downloads and installs packages; may restart some services.
Important note: If it says packages are “kept back”, run the next step.
Step 5) If packages were kept back: full upgrade
sudo apt full-upgrade -y
What it does: Upgrades packages even when dependencies change.
Why it is needed: Kernel and some system updates require dependency changes.
Expected output: Similar to apt upgrade, but may install/remove packages as needed.
Warning: Read the summary; it may remove packages (rare, but possible).
Step 6) Clean up unused packages
sudo apt autoremove -y
What it does: Removes packages no longer required.
Why it is needed: Saves disk space and reduces clutter.
Expected output: A list of packages removed (or nothing to remove).
Step 7) Check if a reboot is required
if [ -f /var/run/reboot-required ]; then echo "Reboot required"; else echo "No reboot required"; fi
What it does: Checks if Ubuntu/Debian marked the system for reboot.
Expected output: Reboot required or No reboot required.
Step 8) Reboot (only if needed)
sudo reboot
What it does: Restarts the server.
Expected result: SSH disconnects. Wait 30–120 seconds, then reconnect.
Final verification
Verify the server is up
uptime
Expected output: Shows load and uptime (after reboot it should be low).
Verify no failed services
systemctl --failed
Expected output: Ideally 0 loaded units listed.
Conclusion
You updated your Ubuntu/Debian server safely. Repeat this regularly (weekly/monthly) to keep your VPS secure.