为什么在 Linux 机器上安装 Java 时使用替代命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16416037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:53:07  来源:igfitidea点击:

Why is alternatives command used when installing Java on a Linux machine

javalinuxshellterminal

提问by Chamara Keragala

The below command is need when installing Java on a Linux machine (saw the command in a tutorial).

在 Linux 机器上安装 Java 时需要以下命令(在教程中看到该命令)。

alternatives --install /usr/bin/java java /usr/java/jre1.7.0_01/bin/java 20000

man alternativescommand on terminal says:

man alternatives终端上的命令说:

alternatives - maintain symbolic links determining default commands

替代方案 - 维护确定默认命令的符号链接

I dont understand why we need this command when installing Java(JRE or JDK), and what does 20000at the end of the line refers to? Please care to explain.

我不明白为什么我们在安装 Java(JRE 或 JDK)时需要这个命令20000,行尾指的是什么?请注意解释。

采纳答案by NeplatnyUdaj

It's not specific to Linux, only some of the distributions. It's better for maintaining multiple versions of the software or libraries and easily switch between them. Your applications are only pointing to the symbolic link, which you can easily switch any time and don't have to go through all the configurations of your applications. I don't know what the 20000 means, but here's the manpage: http://linux.about.com/library/cmd/blcmdl8_alternatives.htm(but you should have that in your system too)

它不是特定于 Linux 的,只是一些发行版。最好是维护软件或库的多个版本并在它们之间轻松切换。您的应用程序仅指向符号链接,您可以随时轻松切换,而不必检查应用程序的所有配置。我不知道 20000 是什么意思,但这是联机帮助页:http: //linux.about.com/library/cmd/blcmdl8_alternatives.htm(但您的系统中也应该有)

回答by rarchibald

To address what the 20000 is for, this is the priority for that particular alternative. Per the man page:

为了解决 20000 的用途,这是该特定替代方案的优先事项。根据手册页:

Each alternative has a priority associated with it. When a link group is in automatic mode, the alternatives pointed to by members of the group will be those which have the highest priority.

每个备选方案都有与其相关联的优先级。当链接组处于自动模式时,组成员指向的选项将是具有最高优先级的选项。

回答by Eero Aaltonen

There is still no goodexplanation on the priority, but it seems larger numbers are considered to have higher priority than smaller numbers.

关于优先级仍然没有很好的解释,但似乎较大的数字被认为比较小的数字具有更高的优先级。

alternatives --display javaalso displays the priority. I noticed /jre-1.4.2 is added with a priority of 1420, so it would make sense the number the priorities according to the version number of the jre.

alternatives --display java还显示优先级。我注意到 /jre-1.4.2 被添加了 1420 的优先级,所以根据 jre 的版本号确定优先级的数量是有意义的。