Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

HOWTO: Check Which Packages Have Updates Available

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

HOWTO: Check Which Packages Have Updates Available

#1 Post by Deluge »

I was searching for a terminal command to display which installed packages have updates available. There may be other/better ways to do this but I thought I would share this method in case it helps somebody. Please feel free to post any other methods available to do this.

apt-get manpage section for simulating and update/install:

Code: Select all

-s, --simulate, --just-print, --dry-run, --recon, --no-act
    No action; perform a simulation of events that would occur but do not actually change the
    system. Configuration Item: APT::Get::Simulate.
List all packages that have upgrades available using apt-get (grep not required here but cuts out unimportant lines):

Code: Select all

$ apt-get -s upgrade | grep "Inst "
Sample output (displays name, currently installed version, version to upgrade to, repository, and platform):

Code: Select all

Inst debconf [1.5.53] (1.5.55 Debian:unstable [all])
Inst libuuid1 [2.25.2-3] (2.25.2-4 Debian:unstable [amd64])
Inst libblkid1 [2.25.2-3] (2.25.2-4 Debian:unstable [amd64])
Inst libmount1 [2.25.2-3] (2.25.2-4 Debian:unstable [amd64])
Inst libpcre3-dev [1:8.35-3.2] (2:8.35-3.3 Debian:unstable [amd64]) []
...
List all packages that have upgrades available and sort alphabetically:

Code: Select all

$ apt-get -s upgrade | grep "Inst " | sort -f
Sample output:

Code: Select all

Inst apt-utils [1.0.9.3] (1.0.9.4 Debian:unstable [amd64])
Inst autopoint [0.19.3-1] (0.19.3-2 Debian:unstable [all])
Inst avahi-autoipd [0.6.31-4+b1] (0.6.31-4+b2 Debian:unstable [amd64])
Inst avahi-daemon [0.6.31-4+b1] (0.6.31-4+b2 Debian:unstable [amd64])
Inst bind9-host [1:9.9.5.dfsg-5] (1:9.9.5.dfsg-7 Debian:unstable [amd64]) []
...
Remove "Inst " from the output:

Code: Select all

$ apt-get -s upgrade | grep "Inst " | sort -f | sed 's/^.....//'
Sample output:

Code: Select all

apt-utils [1.0.9.3] (1.0.9.4 Debian:unstable [amd64])
autopoint [0.19.3-1] (0.19.3-2 Debian:unstable [all])
avahi-autoipd [0.6.31-4+b1] (0.6.31-4+b2 Debian:unstable [amd64])
avahi-daemon [0.6.31-4+b1] (0.6.31-4+b2 Debian:unstable [amd64])
bind9-host [1:9.9.5.dfsg-5] (1:9.9.5.dfsg-7 Debian:unstable [amd64]) []
--- Edit ---

This method does not display packages that are "kept back".
Last edited by Deluge on 2014-12-21 05:30, edited 2 times in total.

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: HOWTO: Check Which Packages Have Updates Available

#2 Post by Head_on_a_Stick »

Thanks for this!

Just to note: APT will always ask for permission before performing upgrades, you just have to make sure you read what is about to be upgraded and never blindly press "y"

FWIW, the gnome-software package in GNOME 3.14 does just what you want -- it can automatically check the repositories and will tell you when (and which) updates are available.
https://packages.debian.org/sid/gnome-software

Only in sid though, unfortunately it looks like it missed the jessie train...
:(
deadbang

User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

#3 Post by Deluge »

You can use --assume-no to force apt-get to automatically decline installing upgrades (must be super user to invoke upgrade without the -s option):

Code: Select all

$ sudo apt-get upgrade --assume-no
I'll have to check out the gnome-software suggestion. Thanks.

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

#4 Post by Deluge »

Here is another way to list available package updates, though it does not display as much information and requires super user privileges. This only shows packages that are not "kept back". I believe that the -u option is not required:

Code: Select all

$ sudo apt-get -u upgrade --assume-no | sed -n '/be\supgraded/,/newly\sinstalled./{//!p}' | sed 's/^..//' | tr " " "\n"
Sample output:

Code: Select all

apt-utils
autopoint
avahi-autoipd
avahi-daemon
bind9-host
...
To list packages that have upgrades available but are "kept back":

Code: Select all

$ sudo apt-get -u upgrade --assume-no | sed -n '/kept\sback:/,/be\supgraded/{//!p}' | sed 's/^..//' | tr " " "\n"
Sample output:

Code: Select all

blt
ffmpeg
gnome-bluetooth
gnome-sushi
gnome-user-share
...
--- Edit ---

This will show all packages, including "kept back":

Code: Select all

$ sudo apt-get -u upgrade --assume-no | sed -n '/kept\sback/,/newly\sinstalled/{//!p}' | grep "  " | sed 's/^..//' | tr " " "\n"
--- Edit ---

The last command will not display anything if there are no "kept back" packages. So it's not recommended for use.
Last edited by Deluge on 2015-10-15 19:50, edited 1 time in total.

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

User avatar
craigevil
Posts: 5391
Joined: 2006-09-17 03:17
Location: heaven
Has thanked: 28 times
Been thanked: 39 times

Re: HOWTO: Check Which Packages Have Updates Available

#5 Post by craigevil »

apt-get update
apt-get dist-upgrade -s

Much simpler and it will show packages you have held as well.
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list

schnuller
Posts: 386
Joined: 2014-11-25 05:05

Re: HOWTO: Check Which Packages Have Updates Available

#6 Post by schnuller »

craigevil wrote:apt-get update
apt-get dist-upgrade -s
Won't "apt-get dist-upgrade" ask you if you want to go on anyway?
(Well: that would probably make the whole how-to superfluous ...).

User avatar
craigevil
Posts: 5391
Joined: 2006-09-17 03:17
Location: heaven
Has thanked: 28 times
Been thanked: 39 times

Re: HOWTO: Check Which Packages Have Updates Available

#7 Post by craigevil »

-s =simulate
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list

schnuller
Posts: 386
Joined: 2014-11-25 05:05

Re: HOWTO: Check Which Packages Have Updates Available

#8 Post by schnuller »

craigevil wrote:-s =simulate
I for one know.
But if apt-get asks anyway if you want to go on or not, why would one want to simulate instead?
Well: it won't hurt. You will have to run apt-get a second time if you decide you want to go on, but i guess this is pointless (to me it is).

To put it different: In 6 years of running Debian i never ran into the problem dealt with by the OP.

User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

#9 Post by Deluge »

Just a note on my previous command: If you want to know how many updates would be installed use the wc -l command:

Code: Select all

$ apt-get upgrade --simulate | grep "Inst " | sort -f | sed 's/^.....//' | wc -l
146
Of course, simply apt-get upgrade --simulate is just as easy, but it prints out a lot more.

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

User avatar
fireExit
Posts: 559
Joined: 2014-11-20 11:22

Re: HOWTO: Check Which Packages Have Updates Available

#10 Post by fireExit »

in jessie, testing and sid

Code: Select all

sudo apt update && apt list --upgradable

Code: Select all

fireexit@jessie:~$ sudo apt update && apt list --upgradable
Ign http://ftp.uk.debian.org jessie InRelease
[...]
Hit http://ftp.uk.debian.org jessie/non-free Translation-en
Fetched 12.9 kB in 2s (6,371 B/s)           
Reading package lists... Done
Building dependency tree       
Reading state information... Done
5 packages can be upgraded. Run 'apt list --upgradable' to see them.
Listing... Done
linux-compiler-gcc-4.8-x86/stable 3.16.7-ckt11-1+deb8u5 amd64 [upgradable from: 3.16.7-ckt11-1+deb8u4]
linux-headers-3.16.0-4-amd64/stable 3.16.7-ckt11-1+deb8u5 amd64 [upgradable from: 3.16.7-ckt11-1+deb8u4]
linux-headers-3.16.0-4-common/stable 3.16.7-ckt11-1+deb8u5 amd64 [upgradable from: 3.16.7-ckt11-1+deb8u4]
linux-image-3.16.0-4-amd64/stable 3.16.7-ckt11-1+deb8u5 amd64 [upgradable from: 3.16.7-ckt11-1+deb8u4]
linux-libc-dev/stable 3.16.7-ckt11-1+deb8u5 amd64 [upgradable from: 3.16.7-ckt11-1+deb8u4]

User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

#11 Post by Deluge »

Thank you fireExit, that is excellent. I had no idea those commands were available. Has that been around for a long time, or is it planned to be a replacement for apt-get, apt-cache, etc.?

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

User avatar
fireExit
Posts: 559
Joined: 2014-11-20 11:22

Re: HOWTO: Check Which Packages Have Updates Available

#12 Post by fireExit »

Deluge wrote:Has that been around for a long time, or is it planned to be a replacement for apt-get, apt-cache, etc.?
since April, 2014;
it won't be (for now) the replacement of apt-get and apt-cache but their "user-friendly counterpart", see man apt, specially
SCRIPT USAGE
The apt(8) commandline is designed as a end-user tool and it may change the output between versions. While it tries to not break backward compatibility there is no guarantee for it either. All features of apt(8) are available in apt-cache(8) and apt-
get(8) via APT options. Please prefer using these commands in your scripts.

User avatar
Deluge
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

#13 Post by Deluge »

Thanks again fireExit. Very helpful and informative.

Code: Select all

$ uname -vro
4.2.0-1-amd64 #1 SMP Debian 4.2.1-2 (2015-09-27) GNU/Linux

jmgibson1981
Posts: 295
Joined: 2015-06-07 14:38
Has thanked: 11 times
Been thanked: 32 times

Re: HOWTO: Check Which Packages Have Updates Available

#14 Post by jmgibson1981 »

Head_on_a_Stick wrote:Thanks for this!

Just to note: APT will always ask for permission before performing upgrades, you just have to make sure you read what is about to be upgraded and never blindly press "y"

FWIW, the gnome-software package in GNOME 3.14 does just what you want -- it can automatically check the repositories and will tell you when (and which) updates are available.
https://packages.debian.org/sid/gnome-software

Only in sid though, unfortunately it looks like it missed the jessie train...
:(
I wouldn't write off blindly hitting Y altogether. I have a script that runs once a week on my server and laptop to check for and run upgrades automatically at 11pm. It runs with the -y switch. However admittedly I only stick with stable. I rely on the well tested and vetted software in the repos. For testing and above -y is a bad choice though, I won't argue that.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: HOWTO: Check Which Packages Have Updates Available

#15 Post by Head_on_a_Stick »

jmgibson1981 wrote:However admittedly I only stick with stable.
Yes indeed, I have myself released a jessie box into the wild with automatic updates enabled and I've not heard anything back since (silence equals success, right?) :)
deadbang

Post Reply