Alternatives are used when the same command is provided by multiple packages. A classic example is busybox, which provides a whole set of commands such as /bin/ls and /bin/find, which are also provided by other packages such as coreutils (/bin/ls) and findutils (/bin/find).
A system for handling alternatives is required to allow the user to choose which version of the command they wish to have installed. It should be possible to install either one, or both, or remove one when both are installed etc, and to have no issues with the packages overwriting files from other packages.
The most common reason for alternatives is to reduce the size of the binaries. But cutting down on features, built in help and error messages and combining multiple binaries into one large binary it's possible to save considerable space. Often users are not expected to use the commands interactively in embedded appliances and therefore these changes have no visible effect to the user. In some situations users may have interactive access, or they may be more advanced users who want shell access on appliances that normal don't provide it, and in these cases they should be able to install the full functional version if they desire.
Most distributions include busybox in place of the full featured version of the commands. The following example shows a typical install in which the find command, which we'll use as an example here, is the busybox version:
root@titan:~$ find --version find --version BusyBox v1.2.1 (2006.12.17-05:10+0000) multi-call binary Usage: find [PATH...] [EXPRESSION] root@titan:~$ which find which find /usr/bin/find
If we now install the full version of find:
root@titan:~$ ipkg install findutils ipkg install findutils Installing findutils (4.2.29-r0) to root... Downloading http://nynaeve.twibble.org/ipkg-titan-glibc//./findutils_4.2.29-r0_sh4.ipk Configuring findutils update-alternatives: Linking //usr/bin/find to find.findutils update-alternatives: Linking //usr/bin/xargs to xargs.findutils
Then we see that the standard version of find changes to the full featured implement ion:
root@titan:~$ find --version find --version GNU find version 4.2.29 Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION root@titan:~$ which find which find /usr/bin/find
Two methods of using the alternatives system are available:
Via the update-alternatives class. This is the simplest method, but is not usable in all situations.
Via directly calling the update-alternatives command.
The update-alternatives class is the provides the simplest method of using alternatives but it only works for a single alternative. For multiple alternatives they need to be manually registered during post install.
Full details on both methods is provided in the update-alternatives class section of the reference manual.