How to Install Java on Raspberry Pi
Java is one of the most mainstream programming dialects used to construct various types of uses and frameworks.
There are two unique executions of Java, Oracle Java and OpenJDK. OpenJDK is an open-source execution of the Java Platform. Prophet Java has a couple of extra business highlights and a permit that licenses just non-business use, for example, individual or advancement use.
This guide discloses how to introduce Java (OpenJDK) on Raspberry Pi with the most recent Raspbian OS running on it.
The standard Raspbian archives incorporate two diverse Java bundles, Java Runtime Environment (JRE) and Java Development Kit (JDK). JRE incorporates the Java virtual machine (JVM), classes, and pairs that permit you to run Java programs. JDK comprise of JRE and advancement/investigating instruments and libraries important to fabricate Java applications.
In the event that you don't know which Java bundle to introduce, the overall suggestion is to adhere to the default OpenJDK (JDK 11) form. Some Java-based applications may require a particular variant of Java, so you ought to counsel the application documentation.
Installing Java 11 on Raspberry Pi
OpenJDK 11 is the default Java improvement and runtime in the most recent Raspbian OS, which depends on Debian 10, Buster.
Run the accompanying orders to introduce the OpenJDK 11 JDK on your Raspberry Pi:
sudo apt update
sudo apt install default-jdk
When the establishment is finished, confirm it by checking the Java variant:
java -version
The yield should look something like this:
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)
That is it! You have effectively introduced Java on your Pi, and you can begin utilizing it.
Installing Java 8 on Raspberry Pi
The past Java LTS form 8 is as yet upheld and generally utilized. On the off chance that your application requires Java 8, introduce it by composing:
sudo apt update
sudo apt install openjdk-8-jdk
Check the establishment by printing the Java rendition :
java -version
The yield should look something like this:
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1+rpi1-b01)
OpenJDK Client VM (build 25.212-b01, mixed mode)
Set the Default Version
On the off chance that you have various Java variants introduced on your Pi, run the java - rendition order to check the default adaptation:
java -version
To change the default adaptation, utilize the update-choices device:
sudo update-alternatives --config java
The yield will look something like beneath:
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 <enter> to keep the current choice[*], or type selection number:
:
You will be given elite of all introduced Java variants. Enter the quantity of the adaptation you need set as the default and press Enter.
JAVA_HOME
Environment Variable
The JAVA_HOME climate variable is utilized by some Java applications to decide the Java establishment area.
To set the JAVA_HOME climate variable, utilize the update-options order to discover where Java is introduced:
sudo update-alternatives --config java
In this model, the establishment ways are as per the following:
OpenJDK 11 is situated at/usr/lib/jvm/java-11-openjdk-armhf/canister/java
OpenJDK 8 is situated at/usr/lib/jvm/java-8-openjdk-armhf/jre/canister/java
When you found the way of the Java establishment, open the/and so forth/climate document:
sudo nano /etc/environment
Accepting you need to set JAVA_HOME to OpenJDK 11, include the accompanying line, toward the finish of the document:
/etc/environment
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-armhf/bin/java"
For changes to produce results on your present shell you can either log out and sign in or run the accompanying source order:
source /etc/environment
To check that the JAVA_HOME variable is set, type:
echo $JAVA_HOME
You should see the way to the Java 11 double:
/usr/lib/jvm/java-11-openjdk-armhf/bin/java
/and so on/climate is a framework wide design document, which is utilized by all clients. On the off chance that you need to set the JAVA_HOME variable on a for each client premise, add the line to the .bashrc or some other arrangement record which is stacked when the client signs in.
Uninstall Java
You can uninstall Java like some other bundle introduced with able .
For instance, to uninstall the default-jdk bundle just run:
sudo well-suited eliminate default-jdk
Conclusion
The most recent LTS variant of OpenJDK is accessible in the default Raspbian vaults, and the establishment is a basic and clear undertaking.
On the off chance that you have any inquiries, don't hesitate to leave a remark.