Wednesday, 13 June 2007

java on Linux

我在Fedora Core 3上已经成功安装了jdk(jdk-1_5_0_02-linux-i586.rpm),其它版本的Linux基本相同,过程如下:

1. 先从网上下载jdk(jdk-1_5_0_02-linux-i586.rpm) ,推荐SUN的官方网站www.sun.com,下载后放在/home目录中,当然其它地方也行。

进入安装目录

#cd /home

#cp jdk-1_5_0_02-linux-i586.rpm /usr/local

#cd /usr/local

给所有用户添加可执行的权限

#chmod +x jdk-1_5_0_02-linux-i586.rpm.bin

#./jdk-1_5_0_02-linux-i586.rpm.bin

此时会生成文件jdk-1_5_0_02-linux-i586.rpm,同样给所有用户添加可执行的权限

#chmod +x jdk-1_5_0_02-linux-i586.rpm

安装程序

#rpm -ivh jdk-1_5_0_02-linux-i586.rpm

出现安装协议等,按接受即可。

2.设置环境变量。

#vi /etc/profile

在最后面加入

#set java environment

JAVA_HOME=/usr/java/jdk-1_5_0_02

CLASSPATH=.:$JAVA_HOME/lib/tools.jar

PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME CLASSPATH PATH

保存退出。

要使JDK在所有的用户中使用,可以这样:

vi /etc/profile.d/java.sh

在新的java.sh中输入以下内容:

#set java environment

JAVA_HOME=/usr/java/jdk-1_5_0_02

CLASSPATH=.:$JAVA_HOME/lib/tools.jar

PATH=$JAVA_HOME/bin:$PATH

export JAVA_HOME CLASSPATH PATH

保存退出,然后给java.sh分配权限:chmod 755 /etc/profile.d/java.sh

3.在终端使用echo命令检查环境变量设置情况。

#echo $JAVA_HOME

#echo $CLASSPATH

#echo $PATH

4.检查JDK是否安装成功。

#java -version

如果看到JVM版本及相关信息,即安装成功!





#################



java on ubuntu:


Selecting the default Java version

If you want to use Sun's Java instead of the open source GIJ (GNU Java bytecode interpreter) you need to set it as default. To list installed JVMs:

update-java-alternatives -l

To select, for example, Sun's JVM as provided in Ubuntu 6.06, run:

sudo update-java-alternatives -s java-1.5.0-sun

You should also edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered.
Adding JDK 1.4 as an alternative

The Blackdown JDK 1.4 does not automatically appear as an alternative upon installation. In order to make it appear, you'll need to create a file such as /usr/lib/jvm/.java-1.4.2-sun.jinfo as described in the man page for update-java-alternatives. Note: the default install location is /usr/lib/j2se/1.4

Manual method: Run:

sudo update-alternatives --config java

and select your preference from the list.

{i} Note: You probably want to do the same with jar, javac, javadoc, javah, javap and javaws:

sudo update-alternatives --config jar

To get common java applications (installed using .deb-packages) to run under your JVM of choice, make sure you also edit the JVM configuration file:

sudo nano /etc/jvm

and add the line:

/usr/lib/j2sdk1.5-sun

Packages such as ant starts the first JVM found in this file.


No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter