Ubuntu下,两种方法安装JDK6及版本间切换

Note: There are 2 ways to install java6 nowadays b/c java6 has been added to the repositories (multiverse)

The following method is if you have the multiverse repository enabled/added to your /etc/apt/sources.list (I won't go covering how to do that here)

To install:
sudo apt-get update
# To install the mozilla plugin remove the # on the next line
sudo apt-get install sun-java6-jdk #sun-java6-plugin
update-java-alternatives --list
# The line above should produce output somewhat similar to:
# java-6-sun 63 /usr/lib/jvm/java-6-sun
# Add the first part of the line above to the end of the next line
sudo update-java-alternatives --set java-6-sun


Now if you want to change java versions just do:
update-java-alternatives --list
sudo update-java-alternatives --set <one of the java versions>

----------------------------------------------------------------------------------------------------------------------------

The following method shows how to install java 6 manually (in case you don't want multiverse repo. enabled for security reasons or if you just want to learn how to do it)

1. Download the Java 6 SDK (Make sure you download the "Linux self-extracting file") from http://java.sun.com/javase/downloads/index.jsp
2. After it has finished downloading you will have a file called jdk-6-linux-i586.bin
3. Run the following in the directory that the file is located in (Change any variables as you see fit)
JDKFILE=jdk-6-linux-i586.bin
JDKFOLDER=jdk1.6.0
JDKPATH=/opt

chmod +x $JDKFILE
sh $JDKFILE
sudo mv $JDKFOLDER $JDKPATH

# Uncomment the following line to have Mozilla browsers (i.e. Firefox) load the Java 6 plugin
# ln -s $JDKPATH/$JDKFOLDER/jre/plugin/i386/ns7/libjavaplugin_oji.so ~/.mozilla/plugins

echo "export JAVA_HOME=$JDKPATH/$JDKFOLDER" >> ~/.bashrc
echo "PATH=/$JAVA_HOME/bin:/$JAVA_HOME/jre/bin:/$PATH" >> ~/.bashrc

source ~/.bashrc

Now you can test to see if java 6 is installed by running: `java -version` and `javac -version`
This should print out something similar to:
joncfoo@A3200:~$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

joncfoo@A3200:~$ javac -version
javac 1.6.0


Now if you have other versions of Java installed and want to use them, the easiest way to do is would be to change the JAVA_HOME variable by doing:
export JAVA_HOME=/another/java/directory
After you have done this, just launch whatever application(s) you need under that version of Java


I hope this is straightforward and to the point. If not feel free to ask me any questions.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值