1、查看系统位数、系统内核
root@ubuntu02:/home# getconf LONG_BIT 64
root@ubuntu02:/home# hostnamectl Static hostname: ubuntu02 Icon name: computer-vm Chassis: vm Machine ID: 3c186d21e7094b71a8889a2d78350c4b Boot ID: cc8cf35b8ad54b68a5a2f07eb4042153 Virtualization: vmware Operating System: Ubuntu 20.04.3 LTS Kernel: Linux 5.11.0-38-generic Architecture: x86-64
2、查看当前java环境
root@ubuntu02:~# java -version //忽略提示,使用安装包进行安装 Command 'java' not found, but can be installed with: apt install openjdk-11-jre-headless # version 11.0.11+9-0ubuntu2~20.04, or apt install default-jre # version 2:1.11-72 apt install openjdk-13-jre-headless # version 13.0.7+5-0ubuntu1~20.04 apt install openjdk-16-jre-headless # version 16.0.1+9-1~20.04 apt install openjdk-17-jre-headless # version 17+35-1~20.04 apt install openjdk-8-jre-headless # version 8u292-b10-0ubuntu1~20.04
3、官网下载最新java jdk安装包
下载地址:https://www.oracle.com/java/technologies/downloads/#java8
root@ubuntu02:/home/software# wget https://download.oracle.com/otn/java/jdk/8u311-b11/4d5417147a92418ea8b615e228bb6935/jdk-8u311-linux-x64.tar.gz
root@ubuntu02:/home/software# tar -xzvf jdk-8u311-linux-x64.tar.gz
root@ubuntu02:/home/software# ls jdk1.8.0_311 jdk-8u311-linux-x64.tar.gz
4、创建安装目录
root@ubuntu02:/home/software# mkdir -p /usr/lib/jdk root@ubuntu02:/home/software# mv jdk1.8.0_311 /usr/lib/jdk //移动至指定目录
5、配置java环境变量
root@ubuntu02:/home/software# vim /etc/profile
#java env
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_311
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
6、立即生效
root@ubuntu02:/home/software# source /etc/profile
7、配置软连接:
root@ubuntu02:/home/software# update-alternatives --install /usr/bin/java java /usr/lib/jdk/jdk1.8.0_311/bin/java 300 update-alternatives: using /usr/lib/jdk/jdk1.8.0_311/bin/java to provide /usr/bin/java (java) in auto mode root@ubuntu02:/home/software# update-alternatives --install /usr/bin/javac javac /usr/lib/jdk/jdk1.8.0_311/bin/javac 300 update-alternatives: using /usr/lib/jdk/jdk1.8.0_311/bin/javac to provide /usr/bin/javac (javac) in auto mode
8、测试安装效果
root@ubuntu02:/home/software# java -version java version "1.8.0_311" Java(TM) SE Runtime Environment (build 1.8.0_311-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)
参考:https://www.cnblogs.com/lfri/p/10437266.html