跳转至

树莓派安装JDK

安装Java11:

sudo apt update
sudo apt install default-jdk

验证安装:

java -version

输出如下:

$ java -version  
 openjdk version "11.0.10" 2021-01-19  
 OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.18.04)  
 OpenJDK Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.18.04, mixed mode)

配置JAVA_HOME环境:

通过 sudo update-alternatives --config java 获取Java安装目录:

  • OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-armhf/bin/java
  • OpenJDK 8 is located at /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java

编辑环境变量:sudo nano /etc/environment

设置:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-armhf/"

使用 source /etc/environment 使变量生效。

原文链接: http://droid10.com/2021/02/25/树莓派安装jdk/ How to Install Java on Raspberry Pi