HOWTO: Check Which Packages Have Updates Available

Share your own howto's etc. Not for support questions!

HOWTO: Check Which Packages Have Updates Available

Postby Deluge » 2014-12-21 01:59

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
Deluge
 
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

Postby Head_on_a_Stick » 2014-12-21 02:36

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...
:(
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10600
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: HOWTO: Check Which Packages Have Updates Available

Postby Deluge » 2014-12-21 03:16

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

Postby Deluge » 2014-12-21 03:27

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
Deluge
 
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

Postby craigevil » 2014-12-21 15:48

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

Much simpler and it will show packages you have held as well.
Debian Sid KDE Kernel 3.17 Thinkpad R40 Intel M 1.3 CPU 2GB RAM Radeon Mobility 7500
Debian - "If you can't apt-get something, it isn't useful or doesn't exist"
Debian upgrade script smxi | sysinfo script inxi
User avatar
craigevil
 
Posts: 5192
Joined: 2006-09-17 03:17
Location: Oz

Re: HOWTO: Check Which Packages Have Updates Available

Postby schnuller » 2014-12-21 17:40

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 ...).
schnuller
 
Posts: 386
Joined: 2014-11-25 05:05

Re: HOWTO: Check Which Packages Have Updates Available

Postby craigevil » 2014-12-22 05:10

-s =simulate
Debian Sid KDE Kernel 3.17 Thinkpad R40 Intel M 1.3 CPU 2GB RAM Radeon Mobility 7500
Debian - "If you can't apt-get something, it isn't useful or doesn't exist"
Debian upgrade script smxi | sysinfo script inxi
User avatar
craigevil
 
Posts: 5192
Joined: 2006-09-17 03:17
Location: Oz

Re: HOWTO: Check Which Packages Have Updates Available

Postby schnuller » 2014-12-22 12:34

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.
schnuller
 
Posts: 386
Joined: 2014-11-25 05:05

Re: HOWTO: Check Which Packages Have Updates Available

Postby Deluge » 2015-10-15 19:59

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
Deluge
 
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

Postby fireExit » 2015-10-15 20:13

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
fireExit
 
Posts: 559
Joined: 2014-11-20 11:22

Re: HOWTO: Check Which Packages Have Updates Available

Postby Deluge » 2015-10-15 21:29

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
Deluge
 
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

Postby fireExit » 2015-10-16 18:45

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
fireExit
 
Posts: 559
Joined: 2014-11-20 11:22

Re: HOWTO: Check Which Packages Have Updates Available

Postby Deluge » 2015-10-18 00:19

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
User avatar
Deluge
 
Posts: 82
Joined: 2010-04-30 01:15
Location: U.S.

Re: HOWTO: Check Which Packages Have Updates Available

Postby jmgibson1981 » 2015-10-21 22:37

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.
jmgibson1981
 
Posts: 80
Joined: 2015-06-07 14:38

Re: HOWTO: Check Which Packages Have Updates Available

Postby Head_on_a_Stick » 2015-10-22 18:15

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?) :)
Don't break DebianHow to report bugs

SharpBang GNU/Linux — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10600
Joined: 2014-06-01 17:46
Location: /dev/chair


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable