首页 > 代码库 > Linux环境JDK安装配置

Linux环境JDK安装配置

jdk下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html


1.先御载linux系统自带的openjdk

[root@localhost ~]# rpm -qa |grep java

java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64

tzdata-java-2012j-1.el6.noarch 

java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.x86_64

[root@localhost ~]# yum -y remove java* tzdata-java


2.解压、安装、配置

# tar -zxvf jdk-7u79-linux-x64.tar

# mv jdk1.7.0_79/ /usr/local/jdk7  //将解压后的目录移动到/usr/local下,并改名为jdk7


设置jdk的环境变量:在最后添加如下语句

# vi /etc/profile

JAVA_HOME=/usr/local/jdk7

JRE_HOME=/usr/local/jdk7/jre

PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

export JAVA_HOME JRE_HOME PATH CLASSPATH


使环境变量立即生效

# source /etc/profile


检验是否安装成功

# java            #检测jdk bin环境

# javac            #检测jdk classpath环境

# java -version      #查看版本

成功,你会看到如下java命令参数使用说明界面


[root@localhost ~]# java

Usage: java [-options] class [args...]

           (to execute a class)

   or  java [-options] -jar jarfile [args...]

           (to execute a jar file)

where options include:

    -d32  use a 32-bit data model if available

    -d64  use a 64-bit data model if available

    -server  to select the "server" VM

                  The default VM is server.


[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


[root@localhost ~]# java -version     查看版本

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)



3.报错解决

1)错误:bash: /usr/local/jdk7/bin/java: /lib/ld-linux.so.2: bad ELF interpreter


没有那个文件或目录是因为64位系统中安装了32位程序

解决方法:yum install glibc.i686



2)报错

[root@localhost ~]# java -version

-bash: /usr/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory


[root@localhost ~]# yum install ld-linux.so.2 -y    //安装ld-linux.so.2包

本文出自 “Dave-技术博客” 博客,请务必保留此出处http://davewang.blog.51cto.com/6974997/1868005

Linux环境JDK安装配置