CentOS5.5下安装jdk7u3

本文详细介绍了如何在CentOS5.5操作系统上安装jdk7u3,包括检查系统已有的jdk版本,以及使用alternatives命令进行多版本管理。

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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值