红联Linux门户
Linux帮助

JDK在Linux系统上安装配置[图文]

发布时间:2015-02-22 09:42:40来源:linux网站作者:sherlock82102

JDK 6 Update 7在Linux系统上安装配置

Sun发布的JDK/JRE有两种版本,一种是.rpm.bin格式的,另一种则是.bin格式的,可以到这个页面去下载。

这里,我下载的是.bin格式的,下载下来以后,文件为jdk-6u7-linux-i586-rpm.bin。


安装

首先需要解压缩,如图所示:
JDK在Linux系统上安装配置[图文]

第一行命令chmod +x jdk-6u7-linux-i586-rpm.bin是为将要进行安装的工具包jdk-6u7-linux-i586-rpm.bin授权;第二行解压缩并执行安装,只要你输入命令./jdk-6u7-linux-i586-rpm.bin,就会显示“Sun Microsystems, Inc. Binary Code License Agreement”,的内容,很长的,一直翻页下去,直到显示Do you agree to the above license terms? [yes or no]这行时,如图所示:
JDK在Linux系统上安装配置[图文]

注:以上图片上传至红联Linux系统教程频道中。

当然要键入yes了,比需要同意上述的协议才能继续安装。

接着,就开始解压缩软件包,并执行安装过程,如下所示:

Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u7-linux-i586.rpm
inflating: sun-javadb-common-10.3.1-4.1.i386.rpm
inflating: sun-javadb-core-10.3.1-4.1.i386.rpm
inflating: sun-javadb-client-10.3.1-4.1.i386.rpm
inflating: sun-javadb-demo-10.3.1-4.1.i386.rpm
inflating: sun-javadb-docs-10.3.1-4.1.i386.rpm
inflating: sun-javadb-javadoc-10.3.1-4.1.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:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html

Press Enter to continue.....

按回车键即可完成安装。


配置

我使用的是Fedora Core 7 Linux系统,GNOME版本为13.8,系统安装完成后,JDK默认的版本为1.5,你可以查看的,如下所示:

[root@shirdrn Download]# java -version
java version "1.5.0"
gij (GNU libgcj) version 4.1.2 20070502 (Red Hat 4.1.2-12)

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.

安装完成后,JDK 6 Update 7被安装到/usr/java/目录下面,因此,配置环境变量,只需要打开/etc/profile文件,并编辑其内容,如下所示:

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

if [ -x /usr/bin/id ]; then
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

unset i
unset pathmunge

export JAVA_HOME=/usr/java/jdk1.6.0_07
export JRE_HOME=/usr/java/jdk1.6.0_07/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

在/etc/profile文件的最后面添加上面的部分即可。

当你安装并且配置完成JDK 6 Update 7,并重新启动系统后,再次查看,可以看到,当前JDK的版本为1.6。

其实,没有重新启动系统,我做了一个小小测试,虽然使用命令java -version查看版本信息,仍然显示JDK的版本是1.5,但是在测试中是按照我指定的JAVA_HOME使用JDK 1.6。