Check Available Updates on Ubuntu/Debian with apt
sudo apt update # refresh the package lists first
apt list --upgradable # packages with a newer version
apt list --upgradable 2>/dev/null | grep -c -i security # how many are security updates
apt-get -s upgrade | grep '^Inst' # simulate: what an upgrade would install
apt list --upgradable only knows what the last apt update downloaded, so run sudo apt update first (apt-daily.timer does that automatically on most servers, but not on every minimal image). The list shows each package with the installed and the new version. Nothing is installed by these commands.
Cheat Sheet
| Task | Command |
|---|---|
| Refresh lists | sudo apt update |
| List upgradable packages | apt list --upgradable |
| Count them | apt list --upgradable 2>/dev/null | tail -n +2 | wc -l |
| Only security updates | apt list --upgradable 2>/dev/null | grep -i security |
| Ubuntu: updates and security count | /usr/lib/update-notifier/apt-check (prints updates;security) |
| Simulate an upgrade | apt-get -s upgrade |
| Simulate incl. new dependencies | apt-get -s dist-upgrade |
| Packages held back | apt-mark showhold |
| Version of one package, available vs installed | apt policy nginx |
| Reboot needed after updates | ls /var/run/reboot-required |
| Which packages need the reboot | cat /var/run/reboot-required.pkgs |
| Automatic security updates status | systemctl status unattended-upgrades |
| Last upgrades | grep ' upgrade ' /var/log/dpkg.log | tail |
Reading the Output
$ apt list --upgradable
Listing...
openssl/jammy-updates,jammy-security 3.0.2-0ubuntu1.18 amd64 [upgradable from: 3.0.2-0ubuntu1.15]
nginx/jammy-updates 1.18.0-6ubuntu14.5 amd64 [upgradable from: 1.18.0-6ubuntu14.4]
The first line is a header, so a raw wc -l is one too high; the cheat sheet command skips it. A package whose repository includes -security (Ubuntu jammy-security, Debian stable-security or Debian-Security) is a security update. apt prints WARNING: apt does not have a stable CLI interface on stderr when its output is not a terminal; 2>/dev/null hides it. For scripts, apt-get -s upgrade with grep '^Inst' is more stable than apt list.
apt-get -s upgrade shows Inst, Conf and Remv lines and ends with a summary like 3 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. The "not upgraded" packages need new dependencies or removals; they are listed by dist-upgrade or apt full-upgrade, and often include the kernel.
Security Updates Only
apt list --upgradable 2>/dev/null | grep -i security
apt-get -s upgrade | grep '^Inst' | grep -i security
On Ubuntu the apt-check helper gives both numbers directly:
/usr/lib/update-notifier/apt-check
12;3
That is 12 updates, 3 of them security (package update-notifier-common). /usr/lib/update-notifier/apt-check --human-readable prints the same in words.
To apply only security updates, use unattended-upgrades: sudo apt install unattended-upgrades and sudo dpkg-reconfigure -plow unattended-upgrades. Check what it would do with sudo unattended-upgrade --dry-run -d.
After Updating: Reboot Needed?
Kernel and libc updates take effect only after a reboot:
ls /var/run/reboot-required && cat /var/run/reboot-required.pkgs
If the file exists, a reboot is pending. needrestart -r l (package needrestart) lists services that run old libraries and need a restart rather than a full reboot.
Common Pitfalls
| Symptom | Cause |
|---|---|
apt list --upgradable shows nothing but you expect updates |
Lists are stale; run sudo apt update |
E: Could not get lock /var/lib/apt/lists/lock |
Another apt process (often unattended-upgrades or apt-daily) is running; wait |
| Count is off by one | The Listing... header line |
Err: or Failed to fetch during apt update |
A repository is unreachable or the signing key expired; the list is then incomplete |
| Some packages are "kept back" | They need new dependencies; use sudo apt full-upgrade after reading what it will do |
Security count is 0 on Debian with apt-check |
apt-check is Ubuntu-specific; use the grep -i security form |
Packages listed but apt upgrade skips one |
The package is on hold: apt-mark showhold |
Get Alerted When Security Updates Are Waiting
Looking at pending updates helps only when you look. In Zuzia you save a command as a scheduled task on the server, run it once a day and turn on "Monitor the result". The task alerts you by email, Slack, Discord, push or SMS when the command fails or its status line says WARNING or CRITICAL, and the output of every run is kept. Exit 0 means OK, 1 a warning and 2 critical.
sec=$(apt-get -s upgrade 2>/dev/null | grep '^Inst' | grep -c -i security)
all=$(apt-get -s upgrade 2>/dev/null | grep -c '^Inst')
[ "$sec" -gt 0 ] && { echo "WARNING - $sec security updates pending ($all total)"; exit 1; }
echo "OK - no security updates pending ($all other updates)"
The check reads the local lists, so it needs apt update to run regularly, which apt-daily.timer does by default. Zuzia does not read your repositories itself: the command you save decides what counts as a problem. Add [ -f /var/run/reboot-required ] && echo "reboot required" if a pending reboot should alert you too.
FAQ
How do I check for available updates on Ubuntu or Debian?
sudo apt update && apt list --upgradable.
How do I see only security updates?
apt list --upgradable 2>/dev/null | grep -i security, or /usr/lib/update-notifier/apt-check on Ubuntu.
Does apt list --upgradable install anything?
No. It only reads. apt-get -s upgrade simulates an upgrade and also changes nothing.
How often should I check?
Once a day is enough for most servers; security releases are published at any time, so daily keeps the delay short.
Why does the count differ from what apt upgrade installs?
Held-back packages and packages that need new dependencies are listed as upgradable but are not installed by apt upgrade. Use apt full-upgrade after reviewing.
Should I apply updates automatically?
Security updates through unattended-upgrades are a common choice; test other updates on staging first and apply them in a maintenance window.
Can I compare the update list over time?
Zuzia keeps the output of every task run, so you can look back at earlier results.