1 去http://java.sun.com/j2se/1.4.2/download.html 下载一个Linux Platform的JDK,建议下载RPM自解压格式的(RPM in self-extracting file,j2sdk-1_4_2_06-linux-i586-rpm.bin);
2. 上载到Linux服务器上,在shell下执行命令:
[root@LinuxServer rpm]# chmod 755 j2sdk-1_4_2_06-linux-i586-rpm.bin [root@LinuxServer rpm]# ./j2sdk-1_4_2_06-linux-i586-rpm.bin |
这时会有一段Sun的协议,敲几次空格键,当询问是否同意的时候,敲yes就可以了。
Sun Microsystems, Inc. Binary Code License Agreement for the JAVATM 2 SOFTWARE DEVELOPMENT KIT (J2SDK), STANDARD EDITION, VERSION 1.4.2_X … Do you agree to the above license terms? [yes or no]yes Unpacking... Checksumming... 0 0 Extracting... UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu). inflating: j2sdk-1_4_2_06-linux-i586.rpm Done. |
3. 程序会自动生成一个j2sdk-1_4_2_06-linux-i586.rpm文件,这是主程序包,下面来安装;
[root@LinuxServer rpm]#rpm –ivh j2sdk-1_4_2_06-linux-i586.rpm Preparing... ########################################### [100%] 1:j2sdk ########################################### [100%] |
4. 设置环境变量
通常都喜欢用export命令直接在shell下设置
[root@LinuxServer rpm]# export JAVA_HOME=/usr/java/j2sdk1.4.2_06 [root@LinuxServer rpm]# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar [root@LinuxServer rpm]# export PATH=$PATH:$JAVA_HOME/bin |
[root@LinuxServer rpm]#vi .bashrc set JAVA_HOME=/usr/java/j2sdk1.4.2_06 export JAVA_HOME set PATH=$PATH:$JAVA_HOME/bin export PATH set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export CLASSPATH |
[root@LinuxServer rpm]# echo $JAVA_HOME /usr/java/j2sdk1.4.2_06/ [root@LinuxServer rpm]# echo $CLASSPATH /usr/java/j2sdk1.4.2_06/lib/dt.jar:/usr/java/j2sdk1.4.2_06/lib/tools.jar [root@LinuxServer rpm]# echo $PATH /usr/java/j2sdk1.4.2_06/bin/:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin [root@LinuxServer rpm]# -version JAVA version "1.4.2_06" JAVA(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03) JAVA HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)JAVA |
5. 环境设置OK,看看JDK是否能正常工作,我们来写一个测试文件test.java
[root@LinuxServer rpm]#vi test.java class test { public static void main(String[] args) { System.out.println("Hello World!"); } } |
保存退出,下面来编译、执行;
[root@LinuxServer text]# javac test.java [root@LinuxServer text]# test Hello World!JAVA |
OK,工作正常。
6. 如果要使某个用户具有运行java命令的权限,只要修改其bash初始化文件即可。
比如要给用户longware以运行java命令的权限,
[root@LinuxServer root]# vi /home/longware/.bashrc set JAVA_HOME=/usr/java/j2sdk1.4.2_06 export JAVA_HOME set PATH=$PATH:$JAVA_HOME/bin export PATH set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export CLASSPATH |
7. 至此,Linux上JDK的安装完毕。