到Sun网站下载自解压安装包jdk-xxxx.bin
安装:
[root@RHEL4 JDK-1.5.0.06]# chmod +x jdk-xxxx.bin
[root@RHEL4 JDK-1.5.0.06]# ./jdk-xxxx.bin
选择安装位置,
J2SDK安装目录: /usr/local/jdk
配置Java环境变量:
在 ~/.bash_profile 里加入下列几行环境变量即可:
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin
export MANPATH=$JAVA_HOME/man
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
然后执行下列操作:
mv /usr/bin/java /usr/bin/java.bak
ln -s /usr/local/jdk/bin/java /usr/bin/java
注销当前用户,重新登录。
下面验证Java环境变量是否生效:
[root@RHEL4 ~]# echo $JAVA_HOME
/usr/local/jdk
[root@RHEL4 ~]# echo $CLASSPATH
.:/usr/local/jdk/lib/dt.jar:/usr/local/jdk/lib/tools.jar:/usr/local/jdk/jre/lib/rt.jar
[root@RHEL4 ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/jdk/bin:/home/lwg/bin:/usr/local/jdk/bin:/usr/local/jdk/bin
[root@RHEL4 ~]# java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
[root@RHEL4 ~]#
环境变量设置OK!
下面测试JDK:
[root@RHEL4 temp]# vim test.java
class test{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
保存,退出,然后编译、执行:
[root@RHEL4 temp]javac test.java
[root@RHEL4 temp]java test
Hello World!
好了,JDK工作正常!
如果要使某个用户具有运行java命令的权限,只要修改其bash初始化文件.bashrc或者.bash_profile即可。
-------------------------------------------------------------------------------------------------