Why is alternatives command used when installing J

2019-02-21 14:38发布

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

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

man alternatives command on terminal says:

alternatives - maintain symbolic links determining default commands

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

3条回答
萌系小妹纸
2楼-- · 2019-02-21 14:57

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)

查看更多
仙女界的扛把子
3楼-- · 2019-02-21 15:04

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

alternatives --display java also 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.

查看更多
小情绪 Triste *
4楼-- · 2019-02-21 15:17

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

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.

查看更多
登录 后发表回答