alternatives命令用法

hackeruncle發表於2016-04-17
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版本。

轉:http://blog.csdn.net/chszs/article/details/4158485

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30089851/viewspace-2082873/,如需轉載,請註明出處,否則將追究法律責任。

相關文章