Java is one of the most popular programming languages used to build various applications and systems. There are two different implementations of Java, Oracle Java and OpenJDK. Among them, OpenJDK is the open-source implementation of the Java platform. Oracle Java has some additional commercial features, and its license only allows non-commercial use. Below is how to install Java (OpenJDK) on Raspberry Pi’s Raspbian OS. Run the following command to install the latest version of JDK, currently OpenJDK 11 JDK:
sudo apt update
sudo apt install default-jdk
After installation, you can verify by checking the version of Java:
java -version
Output:
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.5+10-post-Raspbian-1deb10u1, mixed mode)
Installing Java 8 Java 8 is still widely used. If you need Java 8, the installation command is:
sudo apt update
sudo apt install openjdk-8-jdk
Check the Java version:
java -version
Multiple Java versions do not conflict; if you need to set the default version, you can use the following method. Run the java -version command to confirm the default version. If you need to change the default version, you can use the update-alternatives tool:
sudo update-alternatives --config java
You will see the installed Java versions:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-armhf/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-armhf/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java 1081 manual mode
Press to keep the current choice[*], or type selection number:
Input the version number you want to set as default and press enter.
If you have installed multiple JDK versions and want to set the JAVA_HOME environment variable, you need to edit the /etc/environment file:
sudo nano /etc/environment
Assuming you want to set JAVA_HOME to OpenJDK 11, you can add at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-armhf/bin/java"
The path after that is what the update-alternatives command outputs. Then run the command:
source /etc/environment
Finally, to uninstall the default-jdk package, simply run:
sudo apt remove default-jdk
Links in the article can be clicked to read the original text at the end
More exciting content
Making a motorcycle dashboard with Raspberry Pi
Making a smart pet feeder with Raspberry Pi
Building an intelligent planetary observer based on Raspberry Pi
Handmade metal wireframe craft X-wing clock
Arduino + 280 LEDs DIY music spectrum light
DIY Stanford Pupper 12 DOF Quadruped Robot Dog
Barrier: PC and Raspberry Pi keyboard and mouse sharing solution