您的位置:首页 > 运维架构 > Linux

CentOS5.5下安装jdk7u3

2012-03-03 14:29 387 查看
CentOS5.5下安装jdk7u3

1、所需软件

jdk-7u3-linux-i586.rpm

2、安装jdk

(1)查看系统自带的jdk

[wesley@localhost ~]$ java -version
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK Client VM (build 1.6.0-b09, mixed mode)
(2)使用root用户安装rpm包,jdk会安装在/usr/java/下

[wesley@localhost ~]$ ls
Desktop  jdk-7u3-linux-i586.rpm
[wesley@localhost ~]$ rpm -ivh jdk-7u3-linux-i586.rpm
error: can't create transaction lock on /var/lib/rpm/__db.000
[wesley@localhost ~]$ su
Password:
[root@localhost wesley]# rpm -ivh jdk-7u3-linux-i586.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...
[root@localhost ~]# ls -la /usr/java/
total 32
drwxr-xr-x  3 root root 4096 Feb 19 13:39 .
drwxr-xr-x 15 root root 4096 Feb 19 13:38 ..
lrwxrwxrwx  1 root root   16 Feb 19 13:39 default -> /usr/java/latest
drwxr-xr-x  8 root root 4096 Feb 19 13:39 jdk1.7.0_03
lrwxrwxrwx  1 root root   21 Feb 19 13:39 latest -> /usr/java/jdk1.7.0_03
(3)测试安装是否成功

[root@localhost ~]$ javac
Usage: javac <options> <source files>
where possible options include:
-g                         Generate all debugging info
-g:none                    Generate no debugging info
-g:{lines,vars,source}     Generate only some debugging info
-nowarn                    Generate no warnings
-verbose                   Output messages about what the compiler is doing
-deprecation               Output source locations where deprecated APIs are used
-classpath <path>          Specify where to find user class files and annotation processors
-cp <path>                 Specify where to find user class files and annotation processors
-sourcepath <path>         Specify where to find input source files
-bootclasspath <path>      Override location of bootstrap class files
-extdirs <dirs>            Override location of installed extensions
-endorseddirs <dirs>       Override location of endorsed standards path
-proc:{none,only}          Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path>      Specify where to find annotation processors
-d <directory>             Specify where to place generated class files
-s <directory>             Specify where to place generated source files
-implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding>       Specify character encoding used by source files
-source <release>          Provide source compatibility with specified release
-target <release>          Generate class files for specific VM version
-version                   Version information
-help                      Print a synopsis of standard options
-Akey[=value]              Options to pass to annotation processors
-X                         Print a synopsis of nonstandard options
-J<flag>                   Pass <flag> directly to the runtime system
-Werror                    Terminate compilation if warnings occur
@<filename>                Read options and filenames from file
[root@localhost ~]# java -version
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK Client VM (build 1.6.0-b09, mixed mode)
但是java –version显示还是系统自带的jdk。

(4)用alternatives命令管理多版本

[root@localhost wesley]# /usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2           /usr/lib/jvm/jre-1.4.2-gcj/bin/java

Enter to keep the current selection[+], or type selection number: 2
[root@localhost wesley]# java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-48)

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 wesley]# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_03/bin/java 1
[root@localhost wesley]# /usr/sbin/alternatives --config java

There are 3 programs which provide 'java'.

Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
+ 2           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
3           /usr/java/jdk1.7.0_03/bin/java

Enter to keep the current selection[+], or type selection number: 3
[root@localhost wesley]# java -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: