Ask Your Question

How to stop RPM from leaving multiple versions installed? (solved)

asked 2014-02-17 08:22:46 -0500

nafmo gravatar image

updated 2014-04-29 06:09:00 -0500

I am working on some software where we need to support upgrades from within the software itself. Since we are running it on Fedora/Red Hat/CentOS based systems, we want to provide the software as RPMs. So far it is working. In the upgrade script, I have code to verify that what I get is actually the RPM I expected, and then I call RPM to upgrade it using this command:

rpm -U --percent --oldpackage --replacepkgs filename.rpm

When I run this from within my software, it causes the RPM database to list two entries: the old version and the new version (with the installed files being from the new version, so that part works fine). When I run this manually, I am unable to reproduce this. The old version is not listed to own any files, so if I remove it with "rpm -e filename_oldversion", it leaves the files from the new RPM on my system.

Is there a way to ensure that it really removes the previously installed version from the RPM database?

The "oldpackage" and "replacepkgs" flags are there to allow downgrades (and to allow for ourselves screwing up the version numbering...), and the "percent" is there to report the progress back to the installing process.


With rpm -vv, I see that it reports this error: Full rpm -vv output here

D: %post(vb288-5.0.0_BETA5_23_g8bc524a-1.x86_64): scriptlet start
error: error creating temporary file /var/tmp/rpm-tmp.glhkDM: No such file or directory
error: Couldn't create temporary file for %post(vb288-5.0.0_BETA5_23_g8bc524a-1.x86_64): No such file or directory
D: ========== +++ vb288-5.0.0_BETA5_15_g07a9222-1 x86_64-linux 0x2
D:     erase: vb288-5.0.0_BETA5_15_g07a9222-1 has 349 files
D: %preun(vb288-5.0.0_BETA5_15_g07a9222-1.x86_64): scriptlet start
error: error creating temporary file /var/tmp/rpm-tmp.vb5KzA: No such file or directory
error: Couldn't create temporary file for %preun(vb288-5.0.0_BETA5_15_g07a9222-1.x86_64): No such file or directory
error: vb288-5.0.0_BETA5_15_g07a9222-1.x86_64: erase failed
D: running post-transaction scripts

The script that is calling rpm (or yum) is running as root, but with a non-root group (a fairly recent change), could that cause it? ("id" reports "uid=0(root) gid=987(vb288) groups=0(root),987(vb288)").


Running under strace, I see this being reported for when it tries to write to /var/tmp/:

open("/var/tmp/rpm-tmp.SjDXyG", O_RDWR|O_CREAT|O_EXCL, 0600) = 23
open("/var/tmp/rpm-tmp.b10kPU", O_RDWR|O_CREAT|O_EXCL, 0600) = -1 ENOENT (No such file or directory)
open("/var/tmp/rpm-tmp.Tide68", O_RDWR|O_CREAT|O_EXCL, 0600) = -1 ENOENT (No such file or directory)


The process invoking rpm (or yum) was running with PrivateTmp=true in its systemd description file. If I remove that, everything seems to work as expected (I have had it running like this for a while now, and the problem has disappeared).

edit retag flag offensive close merge delete


Switching to using yum does not seem to alleviate the problem, I still get several versions in the rpm database from time to time.

nafmo gravatar imagenafmo ( 2014-02-20 06:23:45 -0500 )edit

Did rpm -vv print any useful information? Initially i thought of scriplets failing leaving duplicates. You could test this with rpm --noscripts

marcindulak gravatar imagemarcindulak ( 2014-02-20 07:23:35 -0500 )edit

I haven't (yet) been able to reproduce it while running from an interactive terminal, I will need to do some more testing...

nafmo gravatar imagenafmo ( 2014-02-20 09:32:13 -0500 )edit

I'm referring to using these options in the application and catching the std err/out of rpm. If i understand it correctly it's an application run as root that tries to uninstall itself, or some other components?

marcindulak gravatar imagemarcindulak ( 2014-02-20 11:39:02 -0500 )edit

rpm -vv does mention errors, I've edited them into the question above.

nafmo gravatar imagenafmo ( 2014-02-21 02:09:33 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-02-18 04:49:38 -0500

marcindulak gravatar image

I assume you catch exit status - try to run with rpm -vv . Does your spec contain any scriplets? If so read and

A comment: providing an RPM package outside of Fedora/EL repositories is asking for troubles - depending on it's dependencies the package may break the updates of the whole distribution (i had cases like that). Moreover one should not install/remove packages with rpm (well, this is true in an ideal world, see e.g. ), but with yum. If you still want to package RPMS (e.g. for CI reasons - to have a clean build environment from e.g. mock) make your software query dependencies, let user handle installing the dependencies (sudo, su, gui), and use rpm2cpio/cpio to keep your software under e.g. "/usr/local/my_software" (see ). Depending on your software dependencies bypassing rpm database may be better than polluting it. Consider also providing a user with an option to install (and run) the software from $HOME of an unprivileged account (if that makes sense concerning the software functionality).

edit flag offensive delete link more


Well, it is a commercially sold closed-source proprietary product, so publishing it in a repository would mean setting one up ourselves, which is a bit beyond what is practical at the moment (it is one RPM). Besides, I do not want any automatic updates on this, it all needs to be user-driven.

I do have scriplets in the spec file, I've copied them here:

Your suggestion about installing via yum is interesting, I will have a look into that.

nafmo gravatar imagenafmo ( 2014-02-18 06:27:04 -0500 )edit

yum is a wrapper around rpm which takes care of depsolving. If rpm gives the error, it is likely that yum will too. yum doesn't do anything special.

FranciscoD_ gravatar imageFranciscoD_ ( 2014-03-26 03:32:49 -0500 )edit

Question Tools



Asked: 2014-02-17 08:22:46 -0500

Seen: 2,301 times

Last updated: Apr 29 '14