当前位置: 首页>>技术教程>>正文


linux – Ubuntu的/etc/alternatives机制

, ,

问题描述

我试图更好地了解Ubuntu的/etc /alternatives机制。基础很简单:它允许在同一台计算机上安装多个”providers”,并配置默认值。例如,如果您安装了Java SE 5和Java SE 6,则/etc /alternatives句柄将作为您的默认JRE。

我想了解的是:

  1. 是否有将选项添加到的中央注册表?

  2. 创建软件包时,如何配置特定的软件包作为替代?我可以将其设为默认值吗?

最佳方法

Afaik,您使用update-alternatives命令的–install选项创建替代项。如果您想注册一个程序包,可以将此命令添加到程序包post-install脚本中。

您可以通过–set选项或通过将替代组置于自动模式并确保您的软件包具有最高优先级,来将软件包作为安装时的默认软件包。

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

   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.

update-alternatives手册页的相关片段:

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

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/9660.html,未经允许,请勿转载。