前往oracle官网下载jdk

一.liunx安装

首先检测是否安装java

java -version  
echo $JAVA_HOME

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

cd /usr/loacl/src

wget https://download.oracle.com/otn-pub/java/jdk/16.0.1+9/7147401fd7354114ac51ef3e1328291f/jdk-16.0.1_linux-x64_bin.tar.gz?AuthParam=1624613376_ec19e42d21148230717011bb6b607789

tar xzf jdk-16.0.1_linux-x64_bin.tar.gz

mv /user/local/src/jdk-16.0.1_linux-x64_bin.tar.gz /opt/jdk-16.0.1/
cd /opt/jdk-16.0.1/
alternatives --install /usr/bin/java java /opt/jdk-16.0.1/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/jdk-16.0.1/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/jdk-16.0.1/bin/jar 4
alternatives --install /usr/bin/javac javac /opt/jdk-16.0.1/bin/javac 4
alternatives --set jar /opt/jdk-16.0.1/bin/jar
alternatives --set javac /opt/jdk-16.0.1/bin/javac

安装完成,检查版本

java -version    
 
java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)

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

vim /etc/profile
  
export JAVA_HOME=/opt/jdk-16.0.1
export JRE_HOME=/opt/jdk-16.0.1/jre
export PATH=$PATH:/opt/jdk-16.0.1/bin:/opt/jdk-16.0.1/jre/bin

让/etc/profile文件修改后立即生效 ,可以使用如下命令:

source /etc/profile

二.windows安装

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

三:查看是否安装成功

java -version
echo $JAVA_HOME
Last modification:June 25th, 2021 at 05:40 pm
如果觉得我的文章对你有用,请随意赞赏