在Ubuntu10.10下安装JDK5和JDK6 及切换使用

转载地址 http://blog.csdn.net/helen_ling/article/details/6653598

Java 6: for Gingerbread and newer

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"

$ sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"

$ sudo apt-get update

$ sudo apt-get install sun-java6-jdk

Java 5: for Froyo and older

$ sudo add-apt-repository "deb http://archive.canonical.com/ubuntu maverick partner"

$ sudo add-apt-repository "deb http://cz.archive.Ubuntu.com/ubuntu hardy-updates main multiverse"

$ sudo apt-get update

$ sudo apt-get install sun-java5-jdk

修改环境变量

这一步可以直接用文本编辑软件在/etc目录下打开environment文件进行修改,下面用vi进行演示

$sudo cp environment environment-old [说明:这是备份一下配置文件]

$sudo vi /etc/environment

修改配置文件如下:

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

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-1.5.0-sun-1.5.0.22/bin/:/usr/lib/jvm/java-6-sun-1.6.0.26/bin"

CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun-1.5.0.22/lib:/usr/lib/jvm/java-6-sun-1.6.0.26/lib

JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.22:/usr/lib/jvm/java-6-sun-1.6.0.26

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

选择刚刚安装的java替换当前版本的java

$sudo update-alternatives --config javac(编译)

$sudo update-alternatives --config java(运行)

编写一个测试文件Hello.java

public class Hello{

       public static void main(String args[]){

              System.out.println("Hello world");

       }

}

编译$ javac Hello.java,生成Hello.class

运行$ java Hello


阅读更多
想对作者说点什么? 我来说一句

Ubuntu10.10安装JDK5JDK6

helen_ling helen_ling

2011-08-02 13:57:58

阅读数:378

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭