pacman: print number or list of upgradable packages

is there a way to just print list of packages available for upgrade ?

I am using pacman (yay) of arch linux.

Thank you for help

Asked By: Jan Černý

||

The package pacman-contrib includes a script that can list all the pending updates without applying them, called checkupdates. pacman-contrib is in the community repository

pacman-contrib source

checkupdates – print a list of pending updates without touching the
system sync databases (for safety on rolling release distributions).

Answered By: Alex

First you need to update your local package repository databases:
sudo pacman -Sy or pacman -Sy as root.
Pacman then fetches the most recent database from your configured mirrors. (This is not an upgrade, this is just updating the list of available package versions)

Then use this command to list upgradable packages:
pacman -Qu
This command compares the installed versions of packages to the available ones in your local package repository databases. If you skip step one (above), this will likely produce an empty list.

Same applies to yay: yay -Sy; yay -Qu.

Important Note: Arch does not support partial upgrades and running pacman -Sy sets up for exactly that. See Arch Wiki for reference.
If you use this way to check for upgradable packages make sure you always install using pacman -Su $package.
Since it can happen that the package version in your local database does not exist on the mirror anymore I recommend to always upgrade the system when installing a new package anyways.
So at the end its a tradeoff and choice of workflow in my opinion. The alternative of course is the solution mentioned by Alex which includes an extra package to achieve what you asked for, but without updating the systems package database.

Pacman is one of the best package managers out there (in my opinion) and as most of the time the Arch Linux Wiki is a great source of information: Arch Wiki

Answered By: Bone

I have never used yay, but for pacman, you can try something like this (please note you don’t need sudo):

pacman -S -u -p --print-format %n,%v

to get the number you can do the same thing just pipe it to wc -l

Prints a comma separated list of pkgnames,version

In the pacman man-page look for --print & --printf

Answered By: hba