jdk 不同版本的安装及 环境变量的设置

来源:互联网 发布:ps淘宝美工教程 编辑:程序博客网 时间:2024/04/30 00:43

一、下载、解压jdk包:

下面以jdk1.7 为例:

官网文档:http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html#install-64

Installation of the 64-bit JDK on Linux Platforms

This procedure installs the Java Development Kit (JDK) for64-bit Linux, using an archive binary file(.tar.gz).

These instructions use the following file:

    jdk-7u<version>-linux-x64.tar.gz

1. Download the file. Before the file can bedownloaded, you must accept the license agreement. The archivebinary can be installed by anyone (not only root users), in anylocation that you can write to. However, only the root user caninstall the JDK into the system location.

2. Change directory to the location where youwould like the JDK to be installed. Move the.tar.gzarchive binary to the current directory.

3. Unpack the tarball and install the JDK.

    % tar zxvf jdk-7u<version>-linux-x64.tar.gz

The Java Development Kit files are installed in a directorycalled jdk1.7.0_<version> in the currentdirectory.

4. Delete the .tar.gz file if you wantto save disk space.

这样安装就算完成了,使用不同版本的jdk即使用不同版本的安装路径下的 jre 路径下的包。

二、设置环境变量JAVA_HOME

配置java环境变量(参考  http://www.cnblogs.com/mengyan/archive/2012/09/04/2669894.html )

(1)首先在官方网站上下载jdk安装文件,我下载的为:jdk-7u5-linux-i586.tar.gz,当然也可以下载.bin格式的文件,但是这种文件与本文介绍的tar格式的文件在解压缩方面有所不同,这里不再详细介绍;

(2)解压缩该文件,解压后的文件名为:jdk1.7.0_05;将其拷贝到一个文件目录,我放入的是:/home/stopit/software目录,所以当前jdk路径为/home/stopit/software/jdk1.7.0_05,这里将/home/stopit/software/jdk1.7.0_05用xxx替代;

(3)根据上文介绍的几个linux环境变量文件,我们选择profile文件写入我们的环境变量;使用 suodo gedit /etc/proifle  命令打开该文件,并输入以下命令:

#修改java运行环境
export JAVA_HOME="xxx"
export PATH="$PATH:$JAVA_HOME/bin"
export JRE_HOME="$JAVA_HOME/jre"
export CLASSPATH=".:$JAVA_HOME/lib:$JRE_HOME/lib"

(4)修改完成后,使用source /etc/profile 命令进行更新;

(5)下面这几步比较重要,因为在许多linux系统中都预装了openjdk,所以即使上面进行了这些设置,系统默认的还不是我们要设置的内容;如果要真正使用我们自己的jdk,还需要一下步骤:

sudo update-alternatives --install /usr/bin/java java xxx/bin/java 300

sudo update-alternatives --install /usr/bin/javac javac xxx/bin/javac 300

(这里的300只是标识一下,没什么意义,只是下一步要用到)

sudo update-alternatives --config java

执行这步会列出系统上的所有已安装的java,然后自己选择,即选最后为300的那个

sudo update-alternatives --config javac

同上

注意:有些文章上说仅仅使用一下语句即可:
sudo update-alternatives –config java,笔者没有尝试过!

(6)大功告成,使用java -version 命令来查看我们的java环境变量,显示如下内容:

java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)

0 0
原创粉丝点击