您的位置:首页 > 编程语言 > Java开发

多版本jdk共存--alternatives命令用法

2015-12-15 18:49 691 查看
多版本jdk共存--alternatives命令用法

说明:
alternatives是Linux下的一个功能强大的命令,只能在root权限下执行;如系统中有几个命令功能十分类似,却又不能随意删除,那么可以用 alternatives 来指定一个全局的设置
alternatives常用于同一个系统中安装同一软件的多个版本。比如为了开发需要,我需要安装JDK1.6,同时还需要JDK1.7,我怎么样才能忽略安装路径,按照我自己的意思,使用我想要的java版本呢?

使用方法:
[root@localhost tools]# alternatives
alternatives version 1.3.49.3 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: alternatives --install <link> <name> <path> <priority>
[--initscript <service>]
[--slave <link> <name> <path>]*
alternatives --remove <name> <path>
alternatives --auto <name>
alternatives --config <name>
alternatives --display <name>
alternatives --set <name> <path>

common options: --verbose --test --help --usage --version
--altdir <directory> --admindir <directory>
##解释:
alternatives --install <link> <name> <path> <priority>
其中,
install表示安装
link是符号链接 (如:java链接;whereis java;java: /usr/bin/java)
name则是标识符(如:java)
path是执行文件的路径(如:jdk执行文件路径:/usr/java/jdk1.7.0_80/bin/java)
priority则表示优先级


以java的安装为例:
我安装了两个jdk:

/usr/java/jdk1.7.0_80/bin/java
/usr/java/jdk1.6.0_10/bin/java
[root@localhost test]# alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_10/bin/java 3
[root@localhost test]# alternatives --config java

There are 1 programs which provide 'java'.

Selection Command
-----------------------------------------------
*+ 1 /usr/java/jdk1.6.0_10/bin/java

Enter to keep the current selection[+], or type selection number:      #选择标识,这里先不要选,Ctrl+c断开
[root@localhost test]# alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_80/bin/java 4
[root@localhost test]# alternatives --config java

There are 2 programs which provide 'java'.

Selection Command
-----------------------------------------------
*+ 1 /usr/java/jdk1.6.0_10/bin/java
2 /usr/java/jdk1.7.0_80/bin/java

Enter to keep the current selection[+], or type selection number:2     #选择标识2,我这里以jdk1.7为默认的java
用alternatives --config java就可以选择你想要的Java版本
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  alternatives