标签:update-alternatives 命令 ubuntu下自由切换多个jdk环境
安装Ubuntu时,默认安装了OpenJDK_1.7
$ java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.12.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
现在需要安装JDK_1.6
安装在/opt/java/jdk1.6.0_45
/opt/java/jdk1.6.0_45# ls
bin db jre LICENSE README.html THIRDPARTYLICENSEREADME.txt
COPYRIGHT include lib man src.zip
加上环境变量
用户环境变量:~/.bashrc中增加行
export JAVA_HOME=/opt/java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export USE_CCACHE=1
系统环境变量:/etc/profile中增加行
export JAVA_HOME=/opt/java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export USE_CCACHE=1
通过update-alternatives切换软件版本
增加JDK_1.6的命令连接符,使用--install选项
$ sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.6.0_45/bin/java 1062
如需移除,--remove选项
$ sudo update-alternatives --remove /usr/bin/java java /opt/java/jdk1.6.0_45/bin/java 1062
创建默认命令链接 --config
$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------------------------------
* 0 /opt/java/jdk1.6.0_45/bin/java 1062 auto mode
1 /opt/java/jdk1.6.0_45/bin/java 1062 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
Press enter to keep the current choice[*], or type selection number:0
同理Python也可以这样切换
本文出自 “M层” 博客,请务必保留此出处http://mengix.blog.51cto.com/7194660/1860961
标签:update-alternatives 命令 ubuntu下自由切换多个jdk环境
原文地址:http://mengix.blog.51cto.com/7194660/1860961