alt   Alternatives and Galternative   alt

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several terminals installed at once. Debian's alternatives system is a tool that gives the user a way to choose or change a default program with minimal disturbance to menus that utilize that program.

How does this work? A generic (descriptive) name in the filesystem is created to be shared by a set of similar programs. These programs are called alternatives for this generic name. The user can at any time choose the alternative (default) that the generic name shall represent, or the computer will choose the one with the highest priority number (see below). Thereafter, the generic name will do everything that using the actual name of the program will do. There is a real advantage in using the generic name in menus, launchers, etc. When a new program of a similar nature to an old program (for example, geany for leafpad, lxterminal for sakura, etc) is installed, all a user need do to get the computer to use the new program in place of the old program is to make sure the new program is in the set of programs associated with the generic name that includes the two programs, and then change the default for that generic name to the new program. Of course, the menus and computer scripts have to be initially set-up using the generic name. This eliminates the work of changing all of the possibly many items that use the old program to using the new program.

Most Debian-based systems come with several generic apps (sets) already installed. Among these are generally x-www-browser (for web browsers), x-window-manager (for window managers), x-terminal-emulator (for terminals), x-session-manager (for session managers) and gnome-text-editor (for text editors). An exec with the generic name is generally put in /usr/bin, for example, /usr/bin/x-terminal-emulator. Also, each installed generic app should have a text file in /var/lib/dpkg/alternatives/, which will list the alternatives for that app. The actual script linking the generic app to the real apps (alternatives) is contained in a file in /etc/alternatives/. So look in either of these directories to see the names of the generic programs already installed and look in the first one to find out the alternatives in each.

The terminal command to add a new alternative to an established group, or to create a new group (generic program), is the same. For example, to create a generic app for file browsers named x-file-manager (to follow the pattern of naming already used by Debian), which includes pcmanfm:

   sudo update-alternatives --install /usr/bin/x-file-manager x-file-manager /usr/bin/pcmanfm 90 .

The number (90) at the end is a priority number (see above). To add, for example, thunar, to the alternatives for x-file-manager, use the exact same command with thunar in place of pcmanfm. Another example, to add the text editor medit as an alternative for gnome-text-editor:

   sudo update-alternatives --install /usr/bin/gnome-text-editor gnome-text-editor /usr/bin/medit 90 .

To set pcmanfm as the default for x-file-manager:

   sudo update-alternatives --set x-file-manager /usr/bin/pcmanfm ,

or, if you have several file managers in the x-file-manager and want to see and pick one, then use:

   sudo update-alternatives --config x-file-manager .

For another example, see Lxlinux - Oracle Java for the commands setting the alternative for the generic java and javaws to be Oracle Java.

There is an excellent lightweight (about 240 kb) GUI named G-Alternative to do all the above except set-up a new generic program. You can add or delete alternatives, set priorities and pick defaults by just checking a few boxes. See the image on the right, which shows G-Alternatives open. In the left margin is a list of all the generic programs installed on the computer. Highlited is the generic x-terminal-emulator, which produces in the body of the display the list of alternatives associated with x-terminal-emulator. Clicking the Add box pops-up a new small box where you need to add (or find) the path to the exec of the new program you wish to add and choose a priority. Click "OK" and the new program is among the alternatives to choose as default if that is your desire. What could be simpler?