- Keep security updates separate from feature updates. Security patches can be applied automatically; version upgrades should not be.
apt list --upgradableanddnf check-updateshow what will change before anything happens.- Take a snapshot or backup before a manual patch run. People skip the way back, then need it.
- Turn on unattended-upgrades or dnf-automatic for security patches only, and read the emails they send.
- Restarting the affected service is usually enough. Only the kernel and core libraries need a full reboot.
How do I safely apply updates to a Linux server?
Check what will change before you change it. Apply security patches (fixes for known vulnerabilities) first, restart only what needs it, then check the site still works. The order matters: most bad patch nights come from applying everything at once, then hunting for which change broke something.
# 1. Refresh the package lists. Changes nothing yet.
sudo apt update
# 2. See exactly what would be upgraded
apt list --upgradable
# 3. Which of those are SECURITY updates?
apt list --upgradable 2>/dev/null | grep -i security
# 4. Apply security updates only
sudo unattended-upgrade --dry-run -d # preview
sudo unattended-upgrade -d # apply
# 5. Or apply everything, once you have read step 2
sudo apt upgrade
# 6. Does anything need a reboot?
[ -f /var/run/reboot-required ] && cat /var/run/reboot-required.pkgsapt upgrade never removes a package. apt full-upgrade can, so read its output before you confirm.# What is available
sudo dnf check-update
# Security updates only
sudo dnf updateinfo list security
sudo dnf update --security
# Everything
sudo dnf update
# Does anything need a restart?
sudo needs-restarting -r # 0 = no reboot needed
sudo needs-restarting -s # services running on old librariesdnf update --security, so security-only patching is easier on the RHEL family.apt upgrade and apt full-upgrade are not the same
apt upgrade only installs newer versions of what is already there. apt full-upgrade (once called dist-upgrade) removes packages when a dependency needs it, and on a server that can mean removing something a site relies on. Read the summary line before you type y.
What should I check before patching?
- 1Take a snapshot if your provider offers one. It is the only way back that covers everything, including a kernel that will not boot. Take it before you start.
- 2Back up the database separately. A snapshot taken while the database is writing may restore into a broken state. Dump the database first, then take the snapshot.
- 3Check free disk space. Upgrades need room to unpack. /boot in particular fills up with old kernels and then fails mid-upgrade, which is awkward to recover from.
- 4Read the changelog for anything major.
apt changelog nginxbefore upgrading a package your site relies on takes a minute and sometimes saves an evening. - 5Know how you get in if SSH breaks. Console access through your provider's panel, tested before you need it.
# Disk space, especially /boot
df -h / /var /boot
# Old kernels filling /boot (Debian / Ubuntu)
dpkg --list | grep linux-image
sudo apt autoremove --purge
# Database dump before anything else
mysqldump --single-transaction --routines --all-databases \
| gzip > /var/backups/pre-patch-$(date +%F).sql.gz
# Record current versions so you can compare afterwards
dpkg -l > /var/backups/packages-before-$(date +%F).txt
# Anything already broken? Fix it before adding changes.
systemctl --failedRun the whole session inside tmux. If SSH drops mid-upgrade, apt or dnf keeps running and you can reconnect. Without it, a dropped connection part-way through an install leaves the package database locked and half set up.
Should I enable automatic security updates?
Yes, for security patches. A known vulnerability left unpatched for weeks on a server open to the internet is a far bigger risk than a security patch breaking something. Automatic feature upgrades are different, and should stay off.
sudo apt install -y unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades
# /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
};
Unattended-Upgrade::Mail "alerts@example.com";
Unattended-Upgrade::MailReport "on-change";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Automatic-Reboot "false";
# Confirm it is actually running
systemctl status unattended-upgrades
sudo unattended-upgrade --dry-run -dsudo dnf install -y dnf-automatic
# /etc/dnf/automatic.conf
# upgrade_type = security
# apply_updates = yes
# emit_via = email
# email_to = alerts@example.com
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timerupgrade_type = security is the line that matters. The default is default, which applies everything.Automatic-Reboot false, always
Set it to true and a kernel security patch can restart your live server at 6am with no warning and nobody watching. Leave it false, let the tool tell you a reboot is waiting, and schedule it yourself. See rebooting a Linux server safely.
| Update type | Automate? | Why |
|---|---|---|
| Security patches | Yes | Fixes copied back into your current version, with little else changed |
| Regular package upgrades | No | Feature changes can break configuration |
| Kernel updates | Install yes, reboot no | Needs a reboot you schedule |
| Distribution release upgrades | Never | A major change: plan it, test it and do it by hand |
| Third-party repository packages | No | Nobody has tested them against your setup |
What makes automation safe is keeping security patches apart from everything else.
What do I do after applying updates?
# Which services are running against libraries that no longer exist?
sudo needs-restarting -s # RHEL family
sudo checkrestart # Debian, from debian-goodies
# Restart the ones that need it, individually
sudo systemctl restart nginx php8.3-fpm
# Anything failed?
systemctl --failed
sudo journalctl -p err --since '30 min ago'
# Do the versions you care about still work?
nginx -v && php -v && mysql --version
# Test the site from outside the server
curl -s -o /dev/null -w 'HTTP %{http_code} in %{time_total}s\n' https://example.com/Config file prompts need a decision
When apt asks whether to keep your version of a config file or take the package's, keep yours (N, the default). Then compare them with diff /etc/nginx/nginx.conf /etc/nginx/nginx.conf.dpkg-dist and copy across anything new by hand. Taking the package version overwrites your settings.
# What was installed and when
grep ' install \| upgrade ' /var/log/dpkg.log | tail -30 # Debian / Ubuntu
sudo dnf history # RHEL family
# Undo an entire dnf transaction. Genuinely useful.
sudo dnf history undo 42
# Downgrade a single package on Debian / Ubuntu
apt list -a nginx
sudo apt install nginx=1.24.0-1ubuntu1
# Pin it so the next upgrade does not undo your fix
sudo apt-mark hold nginxdnf history undo, which is why a snapshot matters more on Debian and Ubuntu.How often should I patch a production server?
| Type | Frequency | Approach |
|---|---|---|
| Security patches | Automatically, daily | unattended-upgrades or dnf-automatic |
| Critical vulnerabilities | Within 24 hours | By hand, as soon as you hear about it |
| Regular packages | Monthly | Scheduled window, snapshot first |
| Kernel reboots | Monthly, or when required | Announced window, out of hours |
| Distribution upgrades | Before end of support | Test on a copy first, never in place on the live server |
The monthly window takes discipline. Security patching should not need a window at all.
Watch the end-of-life date
Once a release stops getting security updates, apt upgrade keeps reporting that all is well while known vulnerabilities go unpatched. Check your version with hostnamectl against your distribution's support calendar, and plan the move months ahead, not in the last week.
Patching never finishes, and getting it wrong lands on a live site. On G7Cloud, we patch the PHP and web server images every site runs on, and each site runs in its own isolated container, so an update for one site never touches another. See how we maintain WordPress sites, or read WordPress security beyond plugins for the wider picture.
Frequently asked questions
What is the difference between apt upgrade and apt full-upgrade?
apt upgrade installs newer versions of installed packages and never removes anything. apt full-upgrade removes packages when a dependency change needs it. On a live server, start with upgrade, and use full-upgrade only after reading exactly what it wants to remove.
Should I enable automatic updates on a production Linux server?
For security patches, yes. They are narrow fixes, and leaving a known vulnerability unpatched is a far greater risk. Limit the setup to the security source only, and leave automatic reboots off so you decide when the server restarts.
How do I apply only security updates on Ubuntu?
Install unattended-upgrades and run sudo unattended-upgrade -d, with Allowed-Origins limited to ${distro_id}:${distro_codename}-security. apt has no --security flag, which is why the tool exists. On the RHEL family, run dnf update --security.
Do I need to reboot after every Linux update?
No. Only kernel and core library updates need one. Check /var/run/reboot-required on Debian and Ubuntu, or needs-restarting -r on the RHEL family. For everything else, restarting the affected service is enough and far less disruptive.
What should I do when apt asks about a modified config file?
Keep your version, which is the default. Then compare afterwards with diff /etc/service/conf /etc/service/conf.dpkg-dist and copy any new options across by hand. Taking the package's version overwrites your settings, and is the usual reason a service fails to start after patching.
How do I roll back a Linux update that broke something?
On the RHEL family, sudo dnf history then sudo dnf history undo <id> reverses a whole transaction. Debian and Ubuntu have no equivalent: downgrade single packages with apt install package=version and hold them. That is why a snapshot beforehand matters more there.
About G7Cloud Engineering
Articles written by the engineers who build and run G7Cloud: UK managed hosting and the AI Website Builder. We write about what we operate every day: containers, backups, databases, and the small-business websites that run on them.
More about G7Cloud →