linux 安装jdk1.7 环境

1.创建目录
mkdir /usr/java
cd  /usr/java
2.下载jdk,网址 http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html ,然后解压到指定目录
tar -xvf jdk-7u79-linux-x64.tar.gz -C /usr/java
3.设置环境变量
[root@master ~]# vi /etc/profile
在profile中添加如下内容:
JAVA_HOME=/usr/java/jdk1.7.0_79
JRE_HOME=/usr/java/jdk1.7.0_79/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效:
[root@master ~]# source /etc/profile

4.验证JDK有效性

[root@localhost java]# java -version
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.4) (rhel-1.41.1.10.4.el6-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
发现版本还是1.6.0_22

由于系统中可能会有默认的其他版本JDK,所以,为了将我们安装的JDK设置为默认JDK版本,还要进行如下操作:
update-alternatives --install /usr/bin/java java    /usr/java/jdk1.7.0_79/bin/java 300
update-alternatives --install /usr/bin/javac javac  /usr/java/jdk1.7.0_79/bin/javac 300
update-alternatives --install /usr/bin/jar jar      /usr/java/jdk1.7.0_79/bin/jar 300
update-alternatives --install /usr/bin/javah javah  /usr/java/jdk1.7.0_79/bin/javah 300
update-alternatives --install /usr/bin/javap javap  /usr/java/jdk1.7.0_79/bin/javap 300

执行下面命令,设置默认版本,此命令执行后,系统会列出当前存在的各种JDK版本,会提示你选择
[root@master jdk1.7.0_79]# update-alternatives --config java
There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   2           /usr/java/jdk1.7.0_79/bin/java

Enter to keep the current selection[+], or type selection number: 2

最终验证:
[root@master jdk1.7.0_79]# 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)

结论:成功更新到1.7.0_79

posted @ 2018-08-07 11:43  醉城、  阅读(2810)  评论(0编辑  收藏  举报