While doing other maintenance tasks I noticed that dpkg -l
listed about 90 packages with status ri
instead of expected ii
.
I maintain packages solely with apt
and aptitude
and I haven't forced any packages but I regulary do apt install --no-install-recommends ...
to avoid getting unneeded packages. I also try to carefully maintain the "automatically installed" flags and I have 2914 packages with status "automatically installed" (aptitude search '~i~M'
) and 422 packages with status "manually installed" (aptitude search '~i!~M'
).
What could be the reason for packages to have status Remove
+ Inst
(ri
) in dpkg -l
listing when I haven't requested those packages to be removed? It seemed that the packages with this status were packages that I actually want to keep in the system. Could e.g. sudo apt dist-upgrade
cause this without me noticing?
(I know that I can reinstall those packages with apt install --reinstall package-name
to get status back to ii
. I also often purge removed packages and aptitude search '~c'
lists no packages.)
Additional details from another system with the same issue:
$ sudo apt dist-upgrade && sudo apt autoremove && dpkg -l | grep ^ri | wc -l
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
virtualbox-6.0
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
171
So dist-upgrade
nor autoremove
do not touch the 171 packages with ri
status.
Example package with ri
status:
$ dpkg -l ca-certificates-java
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================================-============================-============================-===================================================================================================
ri ca-certificates-java 20160321ubuntu1 all Common CA certificates (JKS keystore)
and additional info for the same package:
$ aptitude show ca-certificates-java
Package: ca-certificates-java
State: installed
Automatically installed: no
Multi-Arch: foreign
Version: ...
$ aptitude why ca-certificates-java
i default-jre-headless Depends openjdk-8-jre-headless
iBA openjdk-8-jre-headless Depends ca-certificates-java
$ apt-mark showhold
virtualbox-6.0
Additional info after reading about possible causes:
As explained in answer https://askubuntu.com/a/802612/50254 the status of these packages can be fixed to match currently installed packages by running (note that the line feed after IFS
is not a typo but this command requires setting IFS
to single linefeed):
export IFS='
'
for i in $(dpkg -l |egrep '^[a-z]i.*' |awk '{print $2" install"}') ; do echo $i|dpkg --set-selections ; done
unset IFS
The reason/cause for this problem is still unknown. The ri
status is supposed to mean that dselect
(old debian package manager nowadays completely replaced by apt
) has used to mark package to be removed from the system and if you actually want to apply those selection states you can run apt-get dselect-upgrade
. See man dpkg
and section "INFORMATION ABOUT PACKAGES" for more information.
The apt install --reinstall package-name
is also okay but it will do more than the minimum change to system to fix the problem.
ri
could have been a dependent of another package that was removed but they weren't removed as maybe the--autoremove
switch forapt
wasn't used. But I don't recommend using--autoremove
as you may remove other needed packages. I wish that part of package management was perfect, but it's not. I have accidentally killed systems because an app set them all for autoremove. – Terrance Jul 16 '21 at 12:50dist-upgrade
norautoremove
do anything to these packages. – Mikko Rantalainen Jul 16 '21 at 13:06dpkg -l | grep -w "ri"
yields nothing on my system, butdpkg -l | grep -w "rc"
does, but thats for config and a completely different scenario. I hope you find an answer! – Terrance Jul 16 '21 at 13:13ri
match this list:dpkg --get-selections | awk '$2 == "deinstall" {print $1}'
. So the question is what process could accidentally markdeinstall
fordselect
when I don't usedselect
for anything? – Mikko Rantalainen Jul 17 '21 at 14:34/var/log/dpkg.log
or maybe something likejournalctl -xe
. I really wish I was experiencing the same issue as it would really help to have a second pair of eyes. Another link that I did find was where the--clear-selections
was ran and caused something similar. It is hard to say if this might have been ran either. https://askubuntu.com/questions/687272/revert-accidental-dpkg-clear-selections?rq=1 – Terrance Jul 17 '21 at 14:51dpkg --clear-selections
, too, but I definitely haven't run that. And I'll not run that after reading what it does. I did also find thatdeinstall
is historically used to signaldpkg
bydselect
that a package should be removed. However, I just checked and I don't even havedselect
installed so that shouldn't be setting incorrect flags. Very interesting problem indeed. My current guess would be that VirtualBox package has executed some wrong commands because both these systems have VirtualBox installed and this problem seems to be pretty rare in general. – Mikko Rantalainen Jul 17 '21 at 14:58journalctl
and it doesn't mention the problematic package during the last 1.5 years I've logs available. The system was installed about 11 months earlier so the error must have happened at that time or whatever causes this doesn't not log tojournalctl
at all. – Mikko Rantalainen Jul 17 '21 at 15:16