centos5.2自带的了jdk,但还是1.4的版本,太老掉牙了,tomcat6都没发跑起来。显然没法满足我们的要求。我们先查看一下,如下所示:
- [root@localhost soft]# java -version
- java version “1.4.2″
- gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)
[root@localhost soft]# java -version
java version “1.4.2″
gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)
注意,根据我在5.2下安装的情况,似乎不卸载自带的1.4,设置jdk6的安装无法生效。为了避免这种情况,我们首先还是卸载掉其自带的1.4版本的jdk。
- [root@localhost soft]# rpm -qa | grep jdk
- [root@localhost soft]# rpm -qa | grep gcj
- libgcj-4.1.2-42.el5
- java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
[root@localhost soft]# rpm -qa | grep jdk
[root@localhost soft]# rpm -qa | grep gcj
libgcj-4.1.2-42.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
上面先确认jdk的具体版本号,然后
- root@localhost jdk1.6.0_11]# yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
- Setting up Remove Process
- Resolving Dependencies………..(开始卸载)
- Removed: java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115
- Dependency Removed: antlr.i386 0:2.7.6-4jpp.2 bsf.i386 0:2.3.0-11jpp.1 bsh.i386 0:1.3.0-9jpp.1 gjdoc.i386 0:0.7.7-12.el5 hsqldb.i386 1:1.8.0.9-1jpp.2 openoffice.org-calc.i386
- 1:2.3.0-6.5.el5 openoffice.org-core.i386 1:2.3.0-6.5.el5 openoffice.org-draw.i386 1:2.3.0-6.5.el5 openoffice.org-graphicfilter.i386 1:2.3.0-6.5.el5 openoffice.org-impress.i386
- 1:2.3.0-6.5.el5 openoffice.org-langpack-zh_CN.i386 1:2.3.0-6.5.el5 openoffice.org-langpack-zh_TW.i386 1:2.3.0-6.5.el5 openoffice.org-math.i386 1:2.3.0-6.5.el5 openoffice.org-
- writer.i386 1:2.3.0-6.5.el5 openoffice.org-xsltfilter.i386 1:2.3.0-6.5.el5 tomcat5-jsp-2.0-api.i386 0:5.5.23-0jpp.7.el5 tomcat5-servlet-2.4-api.i386 0:5.5.23-0jpp.7.el5 xalan-
- j2.i386 0:2.7.0-6jpp.1 xerces-j2.i386 0:2.7.1-7jpp.2 xml-commons-apis.i386 0:1.3.02-0.b2.7jpp.10 xml-commons-resolver.i386 0:1.1-1jpp.12
- Complete!(卸载完成)
root@localhost jdk1.6.0_11]# yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Setting up Remove Process
Resolving Dependencies………..(开始卸载)
Removed: java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115
Dependency Removed: antlr.i386 0:2.7.6-4jpp.2 bsf.i386 0:2.3.0-11jpp.1 bsh.i386 0:1.3.0-9jpp.1 gjdoc.i386 0:0.7.7-12.el5 hsqldb.i386 1:1.8.0.9-1jpp.2 openoffice.org-calc.i386
1:2.3.0-6.5.el5 openoffice.org-core.i386 1:2.3.0-6.5.el5 openoffice.org-draw.i386 1:2.3.0-6.5.el5 openoffice.org-graphicfilter.i386 1:2.3.0-6.5.el5 openoffice.org-impress.i386
1:2.3.0-6.5.el5 openoffice.org-langpack-zh_CN.i386 1:2.3.0-6.5.el5 openoffice.org-langpack-zh_TW.i386 1:2.3.0-6.5.el5 openoffice.org-math.i386 1:2.3.0-6.5.el5 openoffice.org-
writer.i386 1:2.3.0-6.5.el5 openoffice.org-xsltfilter.i386 1:2.3.0-6.5.el5 tomcat5-jsp-2.0-api.i386 0:5.5.23-0jpp.7.el5 tomcat5-servlet-2.4-api.i386 0:5.5.23-0jpp.7.el5 xalan-
j2.i386 0:2.7.0-6jpp.1 xerces-j2.i386 0:2.7.1-7jpp.2 xml-commons-apis.i386 0:1.3.02-0.b2.7jpp.10 xml-commons-resolver.i386 0:1.1-1jpp.12
Complete!(卸载完成)
下面开始手动安装,我用的安装包是jdk-6u11-linux-i586.bin,没有使用red hat平台通用的rpm包。
首先,通过ssh将jdk-6u11-linux-i586.bin上传到/home/xjj/soft下。然后,要给jdk-6u11-linux-i586.bin
分配权限,具体的这里要给它可执行的权限,输入:chmod +x jdk-6u11-linux-i586.bin,这里参数x即使执行权限。
- [root@localhost soft]# chmod +x jdk-6u11-linux-i586.bin
[root@localhost soft]# chmod +x jdk-6u11-linux-i586.bin
然后解压:./jdk-6u11-linux-i586.bin,
- [root@localhost soft]# ./jdk-6u11-linux-i586.bin
[root@localhost soft]# ./jdk-6u11-linux-i586.bin
执行之后会有一堆agreement什么的,一路more下去。接着有个确认安装的,输入yes,然后回车。开始解压。一直到
- Java(TM) SE Development Kit 6 successfully installed.
- .........
- Press Enter to continue.....
- Done.
Java(TM) SE Development Kit 6 successfully installed.
.........
Press Enter to continue.....
Done.
看看解压后的文件先
- [root@localhost soft]# ls
- jdk1.6.0_11 jdk-6u11-linux-i586.bin
- [root@localhost soft]# cd jdk1.6.0_11
- [root@localhost jdk1.6.0_11]# ls
- bin db include lib man README_ja.html register.html register_zh_CN.html src.zip
- COPYRIGHT demo jre LICENSE README.html README_zh_CN.html register_ja.html sample THIRDPARTYLICENSEREADME.txt
[root@localhost soft]# ls
jdk1.6.0_11 jdk-6u11-linux-i586.bin
[root@localhost soft]# cd jdk1.6.0_11
[root@localhost jdk1.6.0_11]# ls
bin db include lib man README_ja.html register.html register_zh_CN.html src.zip
COPYRIGHT demo jre LICENSE README.html README_zh_CN.html register_ja.html sample THIRDPARTYLICENSEREADME.txt
哈哈,看到我们熟悉的东西了吧完成解压。一般都将安装文件放在usr/local下,当然你不这样也拿你没办法。所以,先执行拷贝:
- [root@localhost soft]# mv jdk1.6.0_11 /usr/local
- [root@localhost xjj]# cd ../..
- [root@localhost /]# ls
- bin dev home lost+found misc net proc sbin srv tmp var
- boot etc lib media mnt opt root selinux sys usr
- [root@localhost /]# cd /usr/local
- [root@localhost local]# ls
- bin etc games include jdk1.6.0_11 lib libexec sbin share src
[root@localhost soft]# mv jdk1.6.0_11 /usr/local
[root@localhost xjj]# cd ../..
[root@localhost /]# ls
bin dev home lost+found misc net proc sbin srv tmp var
boot etc lib media mnt opt root selinux sys usr
[root@localhost /]# cd /usr/local
[root@localhost local]# ls
bin etc games include jdk1.6.0_11 lib libexec sbin share src
好了,jdk已经成功搬运到了/usr/local下,然后就是最后一步,设置环境变量了。这里有两中设置,一种是通过export设置临时生效,重启
之后设置会丢失,一种是将设置写入/etc/profile文件中,可以一直生效。所以,最好的设置当然是写入文件中了。先执行下面命令:
- [root@localhost jdk1.6.0_11]# vi /etc/profile
[root@localhost jdk1.6.0_11]# vi /etc/profile
打开profile文件后输入i进入insert模式,在文件中添加如下内容。
- export JAVA_HOME=/usr/local/jdk1.6.0_11
- export PATH=$PATH:$JAVA_HOME/bin
- export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/rt.jar
export JAVA_HOME=/usr/local/jdk1.6.0_11
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/rt.jar
然后esc,输入:x,保存退出。然后需要设置让更改生效:
- [root@localhost local]# source /etc/profile
[root@localhost local]# source /etc/profile
当然,如果你喜欢重启的话,你reboot也可以。
好了看看现在的jdk版本吧:
- [root@localhost local]# java -version
- java version “1.6.0_11″
- Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
- Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
[root@localhost local]# java -version
java version “1.6.0_11″
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)