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版本。

最新文章

  1. Android成长日记-使用ViewFlipper实现屏幕切换动画效果
  2. BitmapData类介绍
  3. 位运算&amp;字节运算
  4. 数据导入问题:[Err] [Imp] 1406 - Data too long for column &#39;linkman&#39; at row 20 [Err] [Imp] INSERT INTO `excel_eprinfo`
  5. 使用vs中的工具进行架构比较
  6. jquery 分页控件2
  7. ms_celeb_1m数据提取(MsCelebV1-Faces-Aligned.tsv)python脚本
  8. 轮播插件、原生js编写,弄懂这个,基本上各种轮播都可以自己写了
  9. 认识enum
  10. codechef Row and Column Operations 题解
  11. 使用fidder进行接口测试
  12. Android Strings.xml To CSV / Excel互转
  13. HashSet remove()
  14. 社会地位即服务, Status as a Service (二): 社交网络的投资回报率 (ROI)
  15. (转)python3-staticmethod与classmethod
  16. js焦点事件:onfocus、onblur、focus()、blur()、select()
  17. September 27th 2017 Week 39th Wednesday
  18. K8S发布解释型语言应用的最佳实践
  19. 安装Docker-ce
  20. Course Selection CodeChef - RIN

热门文章

  1. MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 有什么区别?各适用于什么场合?
  2. eclipse中去掉validate的方法
  3. 为Hadoop集群选择合适的硬件配置
  4. C语言之Bit-wise Operation和Logical Operation
  5. org.apache.http.client.methods.HttpGet 转到定义找不到源代码
  6. Android : Your APK does not seem to be designed for tablets.
  7. 小波变换——哈尔小波,Haar
  8. mysql 用户权限操作
  9. Java -- IO -- 目录
  10. 8 -- 深入使用Spring -- 7...2 MVC框架与Spring整合的思考