一、查看Linux自带的JDK是否已安装
安装好的CentOS会自带OpenJdk,用命令java –version 查看,会有下面的信息:
[root@localhost ~]# java -version java version "1.4.2" gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-46) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [root@localhost ~]# |
二、安装JDK
<1>从SUN下载jdk-1_5_0_12-linux-i586.rpm(jdk-6u25-linux-i586.rpm)
在/usr下新建java文件夹,将安装包放在/usr/java目录下
[root@localhost ~]# mkdir /usr/java [root@localhost ~]# cd /usr/java/ [root@localhost java]# rz rz waiting to receive. 开始 zmodem 传输。 按 Ctrl+C 取消。 100% 46989 KB 6712 KB/s 00:00:07 0 Errorss [root@localhost java]# rz rz waiting to receive. 开始 zmodem 传输。 按 Ctrl+C 取消。 100% 68918 KB 4594 KB/s 00:00:15 0 Errors [root@localhost java]# ls jdk-1_5_0_12-linux-i586.rpm jdk-6u25-linux-i586.rpm [root@localhost java]# |
<2>安装JDK (以jdk-6u25-linux-i586.rpm举例说明)
默认情况下,安装包没有执行权限,给安装包添加执行权限:
[root@localhost java]# ll total 116044 -rw-r--r-- 1 root root 48117502 May 2 2007 jdk-1_5_0_12-linux-i586.rpm -rw-r--r-- 1 root root 70572241 May 21 09:11 jdk-6u25-linux-i586.rpm [root@localhost java]# chmod o+x jdk-6u25-linux-i586.rpm [root@localhost java]# ll total 116044 -rw-r--r-- 1 root root 48117502 May 2 2007 jdk-1_5_0_12-linux-i586.rpm -rw-r--r-x 1 root root 70572241 May 21 09:11 jdk-6u25-linux-i586.rpm [root@localhost java]# |
接下来安装软件包:
[root@localhost java]# rpm -ivh jdk-6u25-linux-i586.rpm Preparing... ########################################### [100%] 1:jdk ########################################### [100%] [root@localhost java]# |
安装包默认会安装在/usr/java下面生成一个jdk1.6.0_25目录
[root@localhost java]# ls default jdk-1_5_0_12-linux-i586.rpm jdk1.6.0_25 jdk-6u25-linux-i586.rpm latest [root@localhost java]# cd jdk1.6.0_25/ [root@localhost jdk1.6.0_25]# ls bin include LICENSE register.html sample COPYRIGHT jre man register_ja.html src.zip demo lib README.html register_zh_CN.html THIRDPARTYLICENSEREADME.txt |
三、配置环境变量
<1>用文本编辑器打开/etc/profile
[root@localhost jdk1.6.0_25]# vi /etc/profile |
<2>在最后加入以下几行
export JAVA_HOME=/usr/java/jdk1.6.0_25 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH |
<3>这样我们就设置好JDK了,执行 source /etc/profile 可以立刻生效
[root@localhost jdk1.6.0_25]# source /etc/profile |
注:reboot之后永久生效
四、查看是否安装成功
[root@localhost jdk1.6.0_25]# java -version java version "1.6.0_25" Java(TM) SE Runtime Environment (build 1.6.0_25-b06) Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing) [root@localhost jdk1.6.0_25]# |
成功了!!!!