Debian – Set apt-get options to tolerate harmless ‘dpkg –force-conflicts’ kludge

aptdebiandpkglinuxpackage-management

A trivially conflicting package foo can be made to work with bar, by running dpkg --force-conflicts -i foo. But eventually it's time to upgrade, and 'apt-get' objects:

% apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 foo : Conflicts: bar but 0.2-1 is installed
E: Unmet dependencies. Try using -f.

Can apt-get be tweaked/forced to tolerate the (pretty much fixed) conflict, then upgrade?

(Quickie existence proof: uninstall foo, then upgrade, then reinstall foo as before. Therefore it is possible, the question is finding the least cumbersome mechanism.)


An example, but this question is not about any two particular packages.

For several years GNU parallel has had a trivial conflict with moretutils; each provides /usr/bin/parallel. dpkg can force co-existence:

# assume 'moreutils' is already installed, and 'parallel' is in
# apt's cache directory.
dpkg --force-conflicts -i /var/cache/apt/archives/parallel_20141022+ds1-1_all.deb

This creates a diversion, renames the moreutils version to /usr/bin/parallel.moreutils. Both programs work, until the user upgrades.

I tried an -o option, but that didn't bring on peace:

apt-get -o Dpkg::Options::="--force-conflicts" install parallel moreutils

Possible -o options number in the hundreds, however…

Best Answer

Since OP asked for a list of commands (with which to change the relevant metadata of the package) in the comments to Gilles' answer, here it is:

# download .deb
apt download parallel
# alternatively: aptitude download parallel

# unpack
dpkg-deb -R parallel_*.deb tmp/

# make changes to the package metadata
sed -i \
  -e '/^Version:/s/$/~nomoreutconfl/' \
  -e '/^Conflicts: moreutils/d' \
  tmp/DEBIAN/control

# pack anew
dpkg-deb -b tmp parallel_custom.deb

# install
dpkg -i parallel_custom.deb

This is under the assumptions that the conflicts line only has moreutils as an entry (and without version restrictions) as was the case in my installation. Otherwise, use '/^Conflicts:/s/\(, \)\?moreutils\( [^,]\+\)\?//' as the second sed script to only remove the relevant part of the line and support version restrictions.

Your installed package won't be overwritten by newer versions from the repository and you have to manually repeat this procedure for every update to the GNU parallel package if you want to keep this package up-to-date.

Related Question