红联Linux门户
Linux帮助

Java JDK在CentOS 5.6上的安装

发布时间:2014-12-14 15:35:58来源:linux网站作者:wangjianming45

Java JDK 在CentOS 5.6上的安装(JDK Installation for CentOS 5.6(64-bit))


1.上传安装文件(jdk-6u26-linux-x64.bin)


2.修改权限

[root@localhost ~]# ls -l /usr/local/jdk-6u26-linux-x64.bin

-rw-r--r-- 1 root root 60569605 Aug  4 21:31 /usr/local/jdk-6u26-linux-x64.bin

[root@localhost ~]# chmod oug+x /usr/local/jdk-6u26-linux-x64.bin

[root@localhost ~]# ls -l /usr/local/jdk-6u26-linux-x64.bin

-rwxr-xr-x 1 root root 60569605 Aug  4 21:31 /usr/local/jdk-6u26-linux-x64.bin


3.执行安装文件

[root@localhost ~]# cd /usr/local

[root@localhost local]# ./jdk-6u26-linux-x64.bin


4.设置环境变量

[root@localhost local]# vim /etc/profile
 
在文件末尾添加以下代码

JAVA_HOME=/usr/local/jdk1.6.0_26

CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

PATH=$PATH:$JAVA_HOME/bin

export JAVA_HOME CLASS_PATH PATH
 
使用source使配置文件立即生效

[root@localhost local]# source /etc/profile


5.测试Java

查看当前Java版本

[root@localhost local]# java -version

java version "1.6.0_26"

Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

编写Java程序测试

[root@localhost local]# cd ~
[root@localhost ~]# vim test.java
public class test
{
public static void
main(String args [ ])
{
System.out.println("This is a java JDK test program!");
}
}
 
编译并执行test

[root@localhost ~]# javac test.java

[root@localhost ~]# java test

This is a java JDK test program!