Ubuntu – Upgrade a diverted package, dpkg error

aptdpkgupgrade

I have installed ack (replacement for grep). In debian based systems, since the package name ack already existed (something completely different), the package is called "ack-grep".

The install instructions mention a way to let the user use the command ack as if it was ack-grep:

On Debian-derived distros, ack is packaged as "ack-grep" because
"ack" already existed. If you simply install via:

$ sudo apt-get install ack-grep 

your ack will be called "ack-grep", which is 167% more characters to
type per invocation. This is tragic for your poor fingers.

To create a local diversion, renaming ack-grep to ack, first install
the ack-grep package as shown above. Then, run:

$ sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep

So far, so good. Now when I try to upgrade my system, apt-get upgrade complains because of the diversion:

Unpacking ack-grep (2.12-2) over (2.12-1) ...
dpkg: error processing archive /var/cache/apt/archives/ack-grep_2.12-2_all.deb (--unpack):
 trying to overwrite `/usr/bin/ack', which is the diverted version of `/usr/bin/ack-grep'

It's good that dpkg found the diversion, and tried to overwrite /usr/bin/ack, but why doesn't it succeed?

I tried to redo the conversion as per the instructions:

$ sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep 
Leaving 'local diversion of /usr/bin/ack-grep to /usr/bin/ack'

, but still upon apt-get upgrade, dpkg complains.

Is this normal? What should I do to update the diversion? Is there a way to automate it, or make it just work the next time I apt-get upgrade?

Best Answer

I found a away to fix it, by removing the diversion first:

dpkg-divert --package ack-grep --local --remove --rename --divert /usr/bin/ack /usr/bin/ack-grep

apt-get upgrade works fine after that.

Related Question