LinuxBasics.org

The community that helps people to run Linux

rss
Table of Contents

Debian update-alternatives

On a typical linux-system, there are several programs which can do the same thing. There are vim, nano, ed and (at least on my system) emacs to edit text files. There are Firefox, Mozilla, Opera, Konqueror and Epiphany (and others) as web-browsers. But also for other tasks, like verifying passwords or displaying postscript files, there are many alternatives to the choice that your distribution has made for you initially.

The problem is to tell the system: “Hey, anytime you want me to make changes to a text-file, give me emacs as editor” or “Passwords have to be checked by ”/usr/local/my/super/password/checker.sh“

Debian (and thus all the derived distros like the ”Buntus“, Knoppix, Mepis, …) has a way of setting up these system alternatives; using update-alternatives is not hard, but the manpage can be confusing on how it is done.

What's in /etc/alternatives?

These alternatives are located in /etc/alternatives. You will see various files in there which are symbolic links. The .gz files are for the man pages while the regular files are for the program itself.

Why not simply change the link to the program we want?

When you update that program using dpkg or apt-get, synaptic, etc., that link will get changed back to what it was before you changed the symlink. There may be other reasons, but that has been the chief reason I took the trouble to learn how to do it like /etc/alternatives/README says.

How to change the default alternative?

In a terminal as root, first find the name of the alternative. Go to /etc/alternatives and do ‘ls’ to see them. Then:

update-alternatives --config <name of alternative>

You will get a numbered list of the alternatives available. Choose the number you want. That’s all you do.

Another approach is to simply do:

update-alternatives --all

You will then be presented with all the various program alternatives and you either hit ENTER for no change or enter the number you want for each set.

How to add a program to the list of alternatives.

This was the hard part for me. It will now become easy for you, if it was not already. Here is what is displayed for the syntax for doing this:

update-alternatives --install <link> <name> <path> <priority>

<name> is the name in /etc/alternatives.
<path> is the name referred to.
<link> is the link pointing to /etc/alternatives/<name>.
<priority> is an integer; options with higher numbers are chosen.

For me the hard part was understanding link and path. name is clearly the name of the alternative, like x-www-browser, or editor. These are the filenames you find in /etc/alternatives and name is what you used above in the ‘update-alternatives –config name-of-alternative’ command. The priority for the alternatives you already have can be seen easily with ‘update-alternatives –list name-of-alternative’. Mine seem to run between 80 and 100. I’m not clear yet on the purpose for priority when we set the program we want to use.

path is the path to the program that you want to run like opt/firefox/firefox

link is simply the name you want to give this alternative like firefox. It is the name you will want to choose when you do ‘update-alternative –config x-www-browser’. I don’t know why they chose the word ‘link’, but that is the way it is.

So to add firefox to my list of x-www-browser and choose it, I would as root do:


update-alternatives --install firefox x-www-browser /opt/firefox/firefox  80
update-alternatives --config x-www-browser

I would choose the number for firefox which should now be in the list and it will be the default browser in X for the oddball program that calls for it. Of course you can already set it as default for most purposes, but when you get to default editor, it becomes a big deal, because so many programs will open an editor. You may not want the default vim, but would rather have something like nano as default.

Do other distros use alternatives?

Most probably. Since alternatives are built into the debian-system, any derived distribution will use it, except they made the effort to disable alternatives. I don’t think many will do that. Distributions that are verified to use alternatives are

GUI for Alternatives: galternatives

There also is a GUI-tool for changing the preferred tool for given tasks. It is called |galternatives, but should also run on KDE. You can install it on the commandline using ”apt-get install galternatives“ (Old-School Debian) or ”sudo apt-get install galternatives" (Ubuntu-style) ;)

Thanks to Gary, who pointed me to this nice tool.


Copyright (c) by the authors.
Prior to editing, authors agreed to license their contributions by the terms of the GPL.
See our licensing page for details.


Linux® is a registered trademark of Linus Torvalds.


 
  tutorials/using/debian_update-alternatives.txt · Last modified: 2008/07/20 19:08

LinuxBasics.org

Start Linux-Course Tutorials Linux Links Security Blog Forum E-mail List Search Online Chat

Site-Info

Help Get in Touch Making of LBo

Wiki-Control

Powered by

Linux Apache DokuWiki Mailman RUTE ht://Dig