为什么我在 `update-alternatives --config java` 中看到两个 java 路径

为什么我在 `update-alternatives --config java` 中看到两个 java 路径

当我sudo update-alternatives --config java在终端输入时,我得到以下输出:-

$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-9-oracle/bin/java              1091      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-8-oracle/jre/bin/java          1081      manual mode
  3            /usr/lib/jvm/java-9-oracle/bin/java              1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

如您所见,有两个完全相同的 Java 路径,/usr/lib/jvm/java-9-oracle/bin/java一个位于第 0 个选项,另一个位于第 3 个选项。为什么会这样?为什么我没有看到 openjdk8 或 java-8-oracle 的这个?

答案1

我相信当您运行时,java --version您将获得java 9但这是您的默认设置。现在 update-alternatives 将向系统显示几个适用程序的选项,并将指示当用户未手动选择时哪个是默认选择,因此可以auto看到twojava 9 的选项。

摘录自man update-alternatives

update-alternatives  creates,  removes, maintains and displays information about the symbolic links comprising
the Debian alternatives system.

It is possible for several programs fulfilling the same or similar functions to be installed on a single  sys‐
   tem  at  the  same  time.   For example, many systems have several text editors installed at once.  This gives
   choice to the users of a system, allowing each to use a different editor, if desired, but makes  it  difficult
   for a program to make a good choice for an editor to invoke if the user has not specified a particular prefer‐
   ence.

Debian's alternatives system aims to solve this problem.  A generic name in the filesystem is  shared  by  all
   files  providing interchangeable functionality.  The alternatives system and the system administrator together
   determine which actual file is referenced by this generic name.  For example, if the text  editors  ed(1)  and
   nvi(1)  are  both installed on the system, the alternatives system will cause the generic name /usr/bin/editor
   to refer to /usr/bin/nvi by default. The system administrator can override this  and  cause  it  to  refer  to
   /usr/bin/ed  instead, and the alternatives system will not alter this setting until explicitly requested to do
   so.

换句话说,它表明您有三个 Java 选择,并且在正常情况下始终会使用其中一个选择。

相关内容