How to List Outdated Packages in Arch Linux Using Pacman Commands


2 views

In Arch Linux, the primary method to check for upgradable packages is using pacman's query functionality. The most straightforward command is:

pacman -Qu

This will display all packages that have newer versions available in the configured repositories. The output shows package names, their currently installed version, and the available newer version.

A typical output looks like this:

linux 5.15.12.arch1-1 -> 5.15.15.arch1-1
python 3.10.2-1 -> 3.10.3-1
firefox 97.0-1 -> 97.0.1-1

Each line represents one package that can be upgraded, showing the current version and the available update.

Using checkupdates Utility

The checkupdates script, part of the pacman-contrib package, provides another way to list available updates without requiring root privileges:

checkupdates

This command parses the pacman database and repository files directly, making it safer for scripting purposes as it doesn't lock the database.

Filtering Foreign Packages

To see only updates for explicitly installed packages (excluding dependencies):

pacman -Quq

Or for a count of upgradable packages:

pacman -Qu | wc -l

For automation purposes, you might want to check if updates are available before proceeding with an upgrade. Here's a simple bash script example:

#!/bin/bash

updates=$(pacman -Qu | wc -l)

if [ $updates -gt 0 ]; then
    echo "$updates packages can be upgraded:"
    pacman -Qu
    # Add your upgrade logic here
else
    echo "System is up to date"
fi

For more complex processing of update information, you can pipe the output to other tools. For example, to get just package names:

pacman -Qu | cut -d' ' -f1

Or to output in JSON format for integration with monitoring systems:

pacman -Qu | awk 'BEGIN {print "["} {print "  {\"package\": \"" $1 "\", \"current\": \"" $2 "\", \"available\": \"" $4 "\"}"} END {print "]"}'

When checking for updates in scripts:

  • Always refresh the package database first with pacman -Sy if you need current information
  • Be aware that running as root may lock the database
  • The checkupdates method is preferred for cron jobs

In Arch Linux, the pacman package manager provides a straightforward way to check which packages are outdated. Instead of directly upgrading all packages with pacman -Syu, you can first list the upgradable packages using:

pacman -Qu

This command will display all packages that have newer versions available in the configured repositories.

The output format shows each outdated package with its current version and the available new version:

lib32-nvidia-utils 535.113.01-1 -> 535.113.01-2
linux 6.4.10.arch1-1 -> 6.4.11.arch1-1

For a cleaner output without dependency information, you can use the checkupdates utility from the pacman-contrib package:

checkupdates

First install it if you don't have it:

sudo pacman -S pacman-contrib

To list only explicitly installed packages that need upgrading:

pacman -Qequ

For foreign packages (AUR packages):

pacman -Qmqu

Here's a simple bash script to count outdated packages:

#!/bin/bash
outdated=$(pacman -Qu | wc -l)
echo "$outdated packages need updating"

To specifically check for security updates (marked in the repository):

pacman -Qu | grep -i security

If you use yay as your AUR helper, you can check both official and AUR packages:

yay -Qu