Ubuntu 的 /etc/alternatives 机制

Ubuntu 的 /etc/alternatives 机制

我正在尝试更好地理解 Ubuntu 的 /etc/alternatives 机制。基本原理很简单:它允许在同一台机器上安装多个“提供程序”,并配置哪个是默认提供程序。例如,如果您安装了 Java SE 5 和 Java SE 6,/etc/alternatives 会处理哪个是您的默认 JRE。

我想了解的是:

  1. 是否存在一个可以添加选项的中央注册表?
  2. 创建包时,如何配置特定包作为备选包?我可以将其设为默认包吗?

答案1

据我所知,你可以使用- 安装选项更新替代方案命令。如果您想注册一个包作为替代方案,则可以将此命令添加到包安装后脚本中。

您可以通过以下方式将您的软件包设置为安装时的默认软件包- 放选项或将替代组置于自动模式并确保您的包具有最高优先级。

没有中央存储库,只有此命令使用的两个目录:

   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‐
          mation.

相关片段更新替代方案手册页:

   --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.

相关内容