RedHat 5.2 安装jdk 6和tomcat 7
软件准备:
[红帽企业.Linux.5].TLF-SOFT-RedHat.Enterprise.Linux.5.Update.2-XiSO.iso
jdk-6u22-linux-i586-rpm.bin
apache-tomcat-7.0.4.tar.gz or apache-tomcat-7.0.4-src.tar.gz
安装JDK之前检查,在redhat5企业版中默认安装了jdk1.4,需要卸载
[root@javasrv ~]# java --version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)
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@javasrv ~]# yum remove java
Loading "security" plugin
Loading "rhnplugin" plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115 set to be erased
--> Processing Dependency: java-gcj-compat for package: antlr
--> Processing Dependency: java-gcj-compat for package: antlr
--> Processing Dependency: java-gcj-compat >= 1.0.64 for package: gjdoc
--> Processing Dependency: java-gcj-compat >= 1.0.64 for package: gjdoc
--> Running transaction check
---> Package antlr.i386 0:2.7.6-4jpp.2 set to be erased
---> Package gjdoc.i386 0:0.7.7-12.el5 set to be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Removing:
java-1.4.2-gcj-compat i386 1.4.2.0-40jpp.115 installed 441
Removing for dependencies:
antlr i386 2.7.6-4jpp.2 installed 2.5 M
gjdoc i386 0.7.7-12.el5 installed 1.7 M
Transaction Summary
=============================================================================
Install 0 Package(s)
Update 0 Package(s)
Remove 3 Package(s)
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : antlr ######################### [1/3]
Erasing : gjdoc ######################### [2/3]
Erasing : java-1.4.2-gcj-compat ######################### [3/3]
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 gjdoc.i386 0:0.7.7-12.el5
Complete!
[root@javasrv ~]#
安装JDK环境,JDK6.0即java 1.6.0
[root@javasrv ~]# cd /usr/local/src
[root@javasrv src]# chmod 755 jdk-6u22-linux-i586-rpm.bin
[root@javasrv src]# ./jdk-6u22-linux-i586-rpm.bin //安装后生成目录/usr/java
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u22-linux-i586.rpm
inflating: sun-javadb-common-10.5.3-0.2.i386.rpm
inflating: sun-javadb-core-10.5.3-0.2.i386.rpm
inflating: sun-javadb-client-10.5.3-0.2.i386.rpm
inflating: sun-javadb-demo-10.5.3-0.2.i386.rpm
inflating: sun-javadb-docs-10.5.3-0.2.i386.rpm
inflating: sun-javadb-javadoc-10.5.3-0.2.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Sun products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the Sun Product Registration form for
the JDK will be presented. If you do not register, none of
this information will be saved. You may also register your
JDK later by opening the register.html file (located in
the JDK installation directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
Press Enter to continue.....
Done.
[root@javasrv src]# ll /usr/java
total 4
lrwxrwxrwx 1 root root 16 Jul 3 19:26 default -> /usr/java/latest
drwxr-xr-x 9 root root 4096 Jul 3 19:26 jdk1.6.0_22
lrwxrwxrwx 1 root root 21 Jul 3 19:26 latest -> /usr/java/jdk1.6.0_22
配置环境变量
修改/etc/profile文件(系统级别有效)
[root@javasrv src]# vi /etc/profile
JAVA_HOME=/usr/java/default
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH
[root@javasrv src]# source /etc/profile
[root@javasrv src]# java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
修改.bashrc文件(当前用户有效)
[root@javasrv src]# vi ~/.bashrc
JAVA_HOME=/usr/java/default
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH
验证java环境
[root@javasrv src]# more HelloWorld.java
/* HelloWorld.java */
public class HelloWorld {
public static void main(String arg[]) {
System.out.println("Hello, World!");
}
}
[root@javasrv src]# javac HelloWorld.java
编译生成的“HelloWorld.class”
[root@javasrv src]# java HelloWorld //没有扩展名
Hello, World!
命令执行成功