首页 » Linux » 阅读文章

centos5.2下手动安装JDK6

2010-08-03 16:45 9938 5 发表评论

centos5.2自带的了jdk,但还是1.4的版本,太老掉牙了,tomcat6都没发跑起来。显然没法满足我们的要求。我们先查看一下,如下所示:

Java代码
1.[root @localhost soft]# java -version
2.java version “1.4 . 2 ″
3.gij (GNU libgcj) version 4.1 . 2 20071124 (Red Hat 4.1 . 2 – 42 )
Java代码
1.[root@localhost soft]# java -version
2.java version “1.4.2″
3.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。

Java代码
1.[root @localhost soft]# rpm -qa | grep jdk
2.[root@localhost soft]# rpm -qa | grep gcj
3.libgcj-4.1 . 2 – 42 .el5
4.java-1.4 . 2 -gcj-compat- 1.4 . 2.0 -40jpp. 115
Java代码
1.[root@localhost soft]# rpm -qa | grep jdk
2.[root@localhost soft]# rpm -qa | grep gcj
3.libgcj-4.1.2-42.el5
4.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的具体版本号,然后

Java代码
1.root @localhost jdk1. 6 .0_11]# yum -y remove java- 1.4 . 2 -gcj-compat- 1.4 . 2.0 -40jpp. 115
2.Setting up Remove Process
3.Resolving Dependencies………..(开始卸载)
4.Removed: java-1.4 . 2 -gcj-compat.i386 0 : 1.4 . 2.0 -40jpp. 115
5.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
6.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
7.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-
8.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-
9.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
10.Complete!(卸载完成)
Java代码
1.root@localhost jdk1.6.0_11]# yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
2.Setting up Remove Process
3.Resolving Dependencies………..(开始卸载)
4.Removed: java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115
5.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
6.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
7.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-
8.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-
9.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
10.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即使执行权限。

Java代码
1.[root @localhost soft]# chmod +x jdk-6u11-linux-i586.bin
Java代码
1.[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,

Java代码
1.[root @localhost soft]# ./jdk-6u11-linux-i586.bin
Java代码
1.[root@localhost soft]# ./jdk-6u11-linux-i586.bin
[root@localhost soft]# ./jdk-6u11-linux-i586.bin

执行之后会有一堆agreement什么的,一路more下去。接着有个确认安装的,输入yes,然后回车。开始解压。一直到

Java代码
1.Java(TM) SE Development Kit 6 successfully installed.
2……….
3.Press Enter to continue …..
4.Done.
Java代码
1.Java(TM) SE Development Kit 6 successfully installed.
2……….
3.Press Enter to continue…..
4.Done.
Java(TM) SE Development Kit 6 successfully installed.
………
Press Enter to continue…..
Done.

看看解压后的文件先

Java代码
1.[root @localhost soft]# ls
2.jdk1.6 .0_11 jdk-6u11-linux-i586.bin
3.[root@localhost soft]# cd jdk1. 6 .0_11
4.[root@localhost jdk1. 6 .0_11]# ls
5.bin db include lib man README_ja.html register.html register_zh_CN.html src.zip
6.COPYRIGHT demo jre LICENSE README.html README_zh_CN.html register_ja.html sample THIRDPARTYLICENSEREADME.txt
Java代码
1.[root@localhost soft]# ls
2.jdk1.6.0_11 jdk-6u11-linux-i586.bin
3.[root@localhost soft]# cd jdk1.6.0_11
4.[root@localhost jdk1.6.0_11]# ls
5.bin db include lib man README_ja.html register.html register_zh_CN.html src.zip
6.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下,当然你不这样也拿你没办法。所以,先执行拷贝:

Java代码
1.[root @localhost soft]# mv jdk1. 6 .0_11 /usr/local
2.[root@localhost xjj]# cd ../..
3.[root@localhost /]# ls
4.bin dev home lost+found misc net proc sbin srv tmp var
5.boot etc lib media mnt opt root selinux sys usr
6.[root@localhost /]# cd /usr/local
7.[root@localhost local]# ls
8.bin etc games include jdk1.6 .0_11 lib libexec sbin share src
Java代码
1.[root@localhost soft]# mv jdk1.6.0_11 /usr/local
2.[root@localhost xjj]# cd ../..
3.[root@localhost /]# ls
4.bin dev home lost+found misc net proc sbin srv tmp var
5.boot etc lib media mnt opt root selinux sys usr
6.[root@localhost /]# cd /usr/local
7.[root@localhost local]# ls
8.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文件中,可以一直生效。所以,最好的设置当然是写入文件中了。先执行下面命令:

Java代码
1.[root @localhost jdk1. 6 .0_11]# vi /etc/profile
Java代码
1.[root@localhost jdk1.6.0_11]# vi /etc/profile
[root@localhost jdk1.6.0_11]# vi /etc/profile
打开profile文件后输入i进入insert模式,在文件中添加如下内容。

Java代码
1.export JAVA_HOME=/usr/local/jdk1. 6 .0_11
2.export PATH=$PATH:$JAVA_HOME/bin
3.export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/rt.jar
Java代码
1.export JAVA_HOME=/usr/local/jdk1.6.0_11
2.export PATH=$PATH:$JAVA_HOME/bin
3.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,保存退出。然后需要设置让更改生效:

Java代码
1.[root @localhost local]# source /etc/profile
Java代码
1.[root@localhost local]# source /etc/profile
[root@localhost local]# source /etc/profile

当然,如果你喜欢重启的话,你reboot也可以。

好了看看现在的jdk版本吧:

Java代码
1.[root @localhost local]# java -version
2.java version “1.6 .0_11″
3.Java(TM) SE Runtime Environment (build 1.6 .0_11-b03)
4.Java HotSpot(TM) Client VM (build 11.0 -b16, mixed mode, sharing)
Java代码
1.[root@localhost local]# java -version
2.java version “1.6.0_11″
3.Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
4.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)
大功告成!

本文地址:http://www.jwzzsw.com/archives/160.html

文章作者:思悟
版权所有 © 转载时请以链接形式注明作者和原始出处!

评论 共5条 (RSS 2.0) 发表评论

  1. 全集然文明说道:

    祝您幸福!

  2. 雷赞电影网说道:

    哇喔!

  3. 美女图片网说道:

    好文章

  4. 洞口电影网说道:

    路过!

  5. 精美图片网说道:

    偶是来打酱油滴。。

发表评论

联系我 Contact Me

回到页首