I'm trying to better understand Ubuntu's /etc/alternatives mechanism. The basics are easy: it allow for multiple "providers" to be installed on the same machine, and configures which is the default. For instance if you have Java SE 5 and Java SE 6 installed /etc/alternatives handles which is your default JRE.

What I'd like to understand:

  1. Is there a central registry in which the options get added to?
  2. When creating a package, how can I configure a particular package as an alternative? Can I make it the default?

1 Answer 1


Afaik, you create an alternative using the --install option of the update-alternatives command. You can add this command to the package post-install scripts if you wanted to register a package as an alternative.

You can make your package the default on installation through the --set option or by putting the alternative group in automatic mode and ensuring your package has the highest priority.

There is no central repository, just the two two directories used by this command:

   alternatives directory
          A directory, by default /etc/alternatives, containing the symlinks.

   administrative directory
          A directory, by default /var/lib/dpkg/alternatives, containing update-alternatives’ state  infor‐

Relevant snippets of the update-alternatives man page:

   --install genname symlink altern priority [--slave genname symlink altern]...
          Add a group of alternatives to the system.  genname is the generic name for the master link, sym‐
          link is the name of its symlink in the alternatives directory,  and  altern  is  the  alternative
          being  introduced for the master link.  The arguments after --slave are the generic name, symlink
          name in the alternatives directory and the alternative for a slave link.  Zero  or  more  --slave
          options, each followed by three arguments, may be specified.

          If the master symlink specified exists already in the alternatives system’s records, the informa‐
          tion supplied will be added as a new set of alternatives for the group.  Otherwise, a new  group,
          set  to  automatic mode, will be added with this information.  If the group is in automatic mode,
          and the newly added alternatives’ priority is higher than any other  installed  alternatives  for
          this group, the symlinks will be updated to point to the newly added alternatives.

   --set name path
          Set the program path as alternative for name.  This is equivalent to --config but is non-interac‐
          tive and thus scriptable.

   --auto link
          Switch the master symlink link to automatic mode.  In the process, this symlink  and  its  slaves
          are updated to point to the highest priority installed alternatives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.