1、查看Linux自帶的JDK是否已安裝html
安裝好的CentOS會自帶OpenJdk,用命令java –version 查看,會有下面的信息:java
[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 ~]#
|
2、安裝JDKip
<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
|
3、配置環境變量
<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以後永久生效
4、查看是否安裝成功
[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]#
|
成功了!!!!