在Liunx上安装Java环境JDK

前往oracle官网下载jdk

一.liunx安装

首先检测是否安装java

java -version  
echo $JAVA_HOME

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

cd /opt/    
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"    
tar xzf jdk-8u66-linux-x64.tar.gz


cd /opt/jdk1.8.0_66/    
alternatives --install /usr/bin/java java /opt/jdk1.8.0_66/bin/java 2    
alternatives --config java

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

There are 3 programs which provide 'java'.    
    
  Selection    Command    
-----------------------------------------------    
   1           /opt/jdk1.7.0_71/bin/java    
  +2           /opt/jdk1.8.0_45/bin/java    
   3           /opt/jdk1.8.0_51/bin/java    
   4           /opt/jdk1.8.0_66/bin/java    

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

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

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

安装完成,检查版本

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

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

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

重启linux

reboot

二.windows安装

下载后傻瓜式安装,加入环境变量

三:查看是否安装成功

java -version
echo $JAVA_HOME
Last modification:September 27th, 2019 at 03:59 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment