Package conflicts with installed package

Sometimes in the course of portupgrading one package, you'll receive an error about it (or one of its dependencies) conflicting with an installed package (or an earlier version of itself). An example of this error looks something like this:

portupgrade linux_dri

In the course of portupgrading linux_dri in June 2006, for example, the following error message caused the portupgrade to fail:

===> linux_base-fc-4_3 conflicts with installed package(s):
      linux_base-8-8.0_14
 
      They install files into the same place.
      Please remove them first with pkg_delete(1).
*** Error code 1

What happened in this particular example is that linux_dri, which used to have linux_base-8 (Red Hat 8) as a dependency, now depends on linux_base-fc4 (Red Hat Fedora Core 4) instead, and must install this package in order to upgrade properly. The problem is that linux_base-8 and linux_base-fc4 conflict with each other--you cannot have both installed simultaneously. At this point you have to choose whether you want to replace linux_base-8 with linux_base-fc4, forcing packages that still have linux_base-8 as a dependency to use linux_base-fc4 instead, or whether you can live with the current version of linux_dri.

If you decide to continue with the upgrade, we must first uninstall linux_base-8:

pkg_delete -f linux_base-8-8.0_14

The reason why we have to specify the -f flag is because we have packages that depend on this package, and uninstalling it will break all of these packages. An example of some packages that depend on linux_base-8:

acroread7-7.0.1_2,1
linux-XFree86-libs-4.3.99.902_7
linux-atk-1.8.0_2
linux-expat-1.95.7_1
linux-fontconfig-2.2.3_4
linux-glib2-2.4.8_2
linux-gtk2-2.4.14_4
linux-jpeg-6b.33_1
linux-pango-1.6.0_2
linux-png-1.2.8_1
linux-realplayer-10.0.7.785.20060201
linux-tiff-3.6.1_6
linux-winetools-1.25a_2
linux_dri-4.4.0
skype-1.2.0.18
stuffit-5.2.0.611_1

Now that we've removed linux_base-8, we can install linux_base-fc4:

cd /usr/ports/emulators/linux_base-fc4
make install clean

We've installed linux_base-fc4, which should allow us to try portupgrading linux_dri again, this time successfully, but first we have to do a very important step to "unbreak" all of those applications depending on linux_base-8:

pkgdb -F

I'm not going to go over the usage of this tool in detail, because we have another page here dealing with that topic. For our purposes, you need to look for the following prompt (or a similar one:

Stale dependency: acroread7-7.0.1_2,1 -> linux_base-8-8.0_14 (emulators/linux_base-8):
linux_base-fc-4_3 (score:64%) ? ([y]es/[n]o/[a]ll) [no]

Here's the important part. Instead of accepting the default answer of "no", type "all" and hit 'Enter'. This will make linux_base-fc4 the new dependency for every application that depended on linux_base-8, which we uninstalled.

Once that finishes, try launching one of your applications that depended on linux_base-8 but now depends on linux_base-fc4. It should work with the new dependency. You are now free to portupgrade linux_dri:

portupgrade linux_dri

Which should now upgrade smoothly.

This process works fine if the replacement dependency (linux_base-fc4) is compatible with what it replaced (linux_base-8) or with the older version of itself that it replaced. However, sometimes the new version of a package is incompatible with the older version. A good example of this is expat2, which is incompatible with the older version of expat. In addition to the steps we already took, after forcibly upgrading to expat2, one additional step is necessary:

portupgrade -rf expat2

This will rebuild EVERY application that depends on expat--a lot! This will literally take a DAYS on some systems, and in the mean time you will be unable to launch the apps (including X.org!) that depend on expat. My advice would be to only undertake such a big upgrade when you have time you can be without your favorite computer system, or alternatively to launch X and a few graphical apps (like firefox) that you don't think you can live without for the next day or two prior to forcibly uninstalling the old version of expat from your system and installing the new expat2 AND KEEP THOSE APPS RUNNING while the rebuild is in progress. They'll work so long as you don't close them, but once you close them you won't be able to use them again until they've been rebuilt to accept the new libexpat provided by expat2.