1. 下载
https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
2. 解压缩到指定目录
- 创建目录
sudo mkdir /usr/lib/java
- 解压缩到该目录
sudo tar -zxvf jdk-17_linux-x64_bin.tar.gz -C /usr/lib/java
3. 配置
- 修改环境变量
sudo gedit ~/.bashrc
在末尾添加
# Set jdk environment
export JAVA_HOME=/usr/lib/java/jdk-17.0.5 # 注意:这里要改成你自己的目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
使环境变量生效
source ~/.bashrc
- 系统注册此jdk
sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jdk-17.0.5/bin/java 300
4. 查看java版本,测试是否安装成功
java -version
出现如下,表示安装成功
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)
5. 如果安装了多个版本的JDK,可用以下命令进行切换
sudo update-alternatives --config java
标签:Ubuntu20.04,bin,java,lib,jdk,JDK17,usr,HOME,安装
From: https://www.cnblogs.com/rookieveteran/p/16917484.html