您现在的位置是:首页 > 博客日记 > Liunx Liunx

在Liunx上安装Java环境JDK

2018-05-09 14:00:00

java Jdk的安装

安装Java环境
首先检测是否安装java

  1. java -version
  2. echo $JAVA_HOME

如果java的版本过低,建议安装高版本,下面安装的是java 1.8

  1. cd /opt/
  2. wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.tar.gz"
  3. tar xzf jdk-8u66-linux-x64.tar.gz
  4. cd /opt/jdk1.8.0_66/
  5. alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 2
  6. alternatives --config java

运行了上面的,会初选一个选择的地方,我的机器显示:

  1. There are 3 programs which provide 'java'.
  2. Selection Command
  3. -----------------------------------------------
  4. 1 /opt/jdk1.7.0_71/bin/java
  5. +2 /opt/jdk1.8.0_45/bin/java
  6. 3 /opt/jdk1.8.0_51/bin/java
  7. 4 /opt/jdk1.8.0_66/bin/java
  8. Enter to keep the current selection[+], or type selection number: 4

我们安装的是jdk1.8.0.66 所以,我选择的是4,这个看具体情况,jdk1.8.0.66 是第几个,就选择那个数字。

  1. alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_66/bin/jar 2
  2. alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_66/bin/javac 2
  3. alternatives --set jar /opt/jdk1.8.0_66/bin/jar
  4. alternatives --set javac /opt/jdk1.8.0_66/bin/javac

安装完成,检查版本

  1. java -version
  2. java version "1.8.0_66"
  3. Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
  4. Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

保存到文件 /etc/environment中,当服务器重启的时候加载:

  1. vi /etc/profile
  2. export JAVA_HOME=/opt/jdk1.8.0_66
  3. export JRE_HOME=/opt/jdk1.8.0_66/jre
  4. export PATH=$PATH:/opt/jdk1.8.0_66/bin:/opt/jdk1.8.0_66/jre/bin

重启linux

  1. reboot

查看是否安装成功

  1. java -version
  2. echo $JAVA_HOME


关注TinyMeng博客,更多精彩分享,敬请期待!