How to uninstall another package before installing current one with dpkg?

1.2k Views Asked by At

I need to uninstall another package before current package being installed, I tried put dpkg --remove com.foo.foo.another in preinst file, which doesn't work, it throws error dpkg: error: dpkg status database is locked by another process. How can I achieve that? Appreciate!

1

There are 1 best solutions below

6
creker On

You can't do that. Dpkg locks its database for the whole process of installation - none of your scripts will be able to do anything like installing or uninstalling a package.

I had a similar problem. I wanted to install debian package manually during installation of my app. My app had a daemon which I launched as part of installation. To solve my problem in the daemon I waited until dpkg releases the lock and then installed the package. It's very important that I did it in a daemon as it's detached from postinst script, so dpkg can happily finish the installation.

You probably need to do something similar.