歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> alternatives命令用法

alternatives命令用法

日期:2017/2/28 13:45:14   编辑:Linux教程

alternatives是Linux下的一個功能強大的命令。只能在root權限下執行。如系統中有幾個命令功能十分類似,卻又不能隨意刪除,那麼可以用 alternatives 來指定一個全局的設置。

alternatives常用於同一個系統中安裝同一軟件的多個版本。比如為了開發需要,我需要安裝JDK1.4.2,同時還需要JDK1.6.10,我怎麼樣才能忽略安裝路徑,按照我自己的意思,使用我想要的java版本呢?

下面為您一一道來。

alternatives的命令行執行如下:
[root@localhost tools]# alternatives
alternatives version 1.3.36 - 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是符號鏈接
name則是標識符
path是執行文件的路徑
priority則表示優先級

以java的安裝為例,我的Fedora 8下自帶了兩種java版本,分別如下:

Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.7.0-icedtea/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java


我在目錄/tools/jdk安裝了java version "1.4.2_19"
[root@localhost test]# alternatives --install /usr/bin/java java /tools/jdk/bin/java 3
[root@localhost test]# alternatives --config java

There are 3 programs which provide 'java'.

Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.7.0-icedtea/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
3 /tools/jdk/bin/java

Enter to keep the current selection[+], or type selection number: 3


我還在目錄/tools/jdk6下安裝了java version "1.6.0_12"
[root@localhost test]# alternatives --install /usr/bin/java java /tools/jdk6/bin/java 4
[root@localhost test]# alternatives --config java

There are 4 programs which provide 'java'.

Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.7.0-icedtea/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
+ 3 /tools/jdk/bin/java
4 /tools/jdk6/bin/java

Enter to keep the current selection[+], or type selection number: 4

用alternatives --config java就可以選擇你想要的Java版本。

Copyright © Linux教程網 All Rights Reserved