Note 1: At the end of the post I explain why I think this is not a duplicate of this or this question.
Note 2: If you want to avoid wasting too much time in reading the question, you can just read the problem and, if you want, what I tried. The rest of the post just contains details for completeness.
The problem
In the past I upraded, by mistake, a package for which I realized later that I needed to keep the older version I used to have.
Then I downgraded the package, but apparently the newer version stayed in some cache and the aptitude
tool is upgrading it periodically (every 75 minutes more precisely).
How can I prevent this?
Perhaps I should find a way to remove the new version from some cache ?
What I tried
I tried all the most common approaches to hold the package, which are described here and here, with no success.
For example, I tried using dpkg --set-selections
apt-mark hold
, aptitude hold
and the Lock version
feature in Synaptic
.
In particular, the Synaptic
tool even reports the package as locked, but aptitude
still upgrades it, and of course I tried to hold the package using the very aptitude
tool, but the same happens.
After some investigation, I realized that aptitude
installs the newer version by running dpkg
to install a .deb
file in /var/cache/apt/archives/
. Desperately, I even tried the dirty approach to just delete that file, but it is even regenerated (thus I guess it may be downloaded from the web or extracted from some tar/zip file).
Finally, I also tried to completely remove the newer version using apt-get purge
and to install the older version afterwards using apt-get install
and to hold it afterwards. Nothing, it is still upgraded automatically...
Details
Context
Because of compatibility issues in writing some code, after upgrading a package, let's call it thepackage
, I had to change mind and I needed to downgrade it, from a newer version to an older version, say from 1.1
to 1.0
.
Therefore I run something like
dpkg -i thepackage_1.0.deb
But every 75 minutes the files from this package are automatically deleted and replaced with files from the newer version 1.1
, as if some system script is upgrading the package automatically.
What is happening
Then, in order to investigate about the cause, I replaced the rm
tool to delete files with a script I wrote which, before calling the actual rm
(which has been renamed as real_rm
), prints the chain of commands which ended up calling rm
(I did this by getting the PID of each process parent).
Then the log file generated by this script of mine prints something like:
COMMAND: /bin/bash /bin/rm -rf -- /var/lib/dpkg/tmp.ci
CAUSAL CHAIN:
/sbin/init
-> /usr/sbin/cron -f
-> /usr/sbin/CRON -f
-> /bin/sh -c /sbin/maint --mode=cron > /dev/null 2>&1
-> /usr/bin/perl /sbin/maint --mode=cron
-> /usr/bin/perl -I /var/cache/sysmaint/production/vol/linux/ubuntu/16.04/lib/perl /var/cache/sysmaint/production/vol/linux/ubuntu/16.04/maint/017aptitude/maint --nodebug --nosilent --nodryrun --nologperline --colour --nomachineread --trace=none --mode=cron
-> /usr/bin/aptitude -o Dpkg::Options::=--force-confdef -v -y -f install
-> /usr/bin/dpkg --force-confdef --status-fd 57 --unpack --auto-deconfigure /var/cache/apt/archives/thepackage_1.1.deb
From this log, we can see that cron
is periodically running aptitude
by executing
/usr/bin/aptitude -o Dpkg::Options::=--force-confdef -v -y -f install
and this command executes the following subcommand
/usr/bin/dpkg --force-confdef --status-fd 57 --unpack --auto-deconfigure /var/cache/apt/archives/thepackage_1.1.deb
Therefore it seems that aptitude
is being periodically executed to automatically upgrade some packages via dpkg
stored in a cache folder, and one of those packages is thepackage_1.1.deb
.
Note: why I think this is not a duplicate anymore.
I tried all solutions to hold the package described here and here, but they just don't work. I suspect this is a different problem because the package is already in the cache and this may be the reason why the attempts to hold the older version do not work. Perhaps I should find a way to remove it from the cache?