How to Install Java on Raspberry Pi - MS TV Life.COM

How to Install Java on Raspberry Pi

How to Install Java on Raspberry Pi

Java is without doubt one of the hottest programming languages used to construct completely different sorts of functions and programs.

There are two completely different implementations of Java, Oracle Java and OpenJDK. OpenJDK is an open-source implementation of the Java Platform. Oracle Java has just a few extra industrial options and a license that allows solely non-commercial use, akin to private or growth use.

This information explains tips on how to set up Java (OpenJDK) on Raspberry Pi with the newest Raspbian OS operating on it.

The usual Raspbian repositories embrace two completely different Java packages, Java Runtime Atmosphere (JRE) and Java Improvement Equipment (JDK). JRE contains the Java digital machine (JVM), lessons, and binaries that permit you to run Java applications. JDK encompass JRE and growth/debugging instruments and libraries essential to construct Java functions.

If you’re undecided which Java package deal to put in, the overall advice is to stay to the default OpenJDK (JDK 11) model. Some Java-based functions could require a particular model of Java, so you must seek the advice of the applying documentation.

Putting in Java 11 on Raspberry Pi #

OpenJDK 11 is the default Java growth and runtime within the newest Raspbian OS, which is predicated on Debian 10, Buster.

Run the next instructions to put in the OpenJDK 11 JDK in your Raspberry Pi:

sudo apt update
sudo apt install default-jdk

Once the installation is complete, verify it by checking the Java version:

java -version

The output 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’s it! You’ve efficiently put in Java in your Pi, and you can begin utilizing it.

Putting in Java Eight on Raspberry Pi #

The earlier Java LTS model Eight continues to be supported and broadly used. In case your utility requires Java 8, set up it by typing:

sudo apt update
sudo apt install openjdk-8-jdk

Verify the installation by printing the Java version :

java -version

The output 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 #

If you have multiple Java versions installed on your Pi, run the java -version command to check the default version:

java -version

To change the default version, use the update-alternatives tool:

sudo update-alternatives --config java

The output will look something like below:

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’ll be introduced with an inventory of all put in Java variations. Enter the variety of the model you need set because the default and press Enter.

JAVA_HOME Atmosphere Variable #

The JAVA_HOME environment variable is utilized by some Java functions to find out the Java set up location.

To set the JAVA_HOME setting variable, use the update-alternatives command to search out the place Java is put in:

sudo update-alternatives --config java

In this example, the installation paths are as follows:

  • 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

Once you found the path of the Java installation, open the /etc/environment file:

sudo nano /etc/environment

Assuming you want to set JAVA_HOME to OpenJDK 11, add the following line, at the end of the file:

/etc/environment

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

For changes to take effect on your current shell you can either log out and log in or run the following source command:

source /etc/environment

To verify that the JAVA_HOME variable is set, type:

echo $JAVA_HOME

You should see the path to the Java 11 binary:

/usr/lib/jvm/java-11-openjdk-armhf/bin/java

/etc/environment is a system-wide configuration file, which is used by all users. If you want to set the JAVA_HOME variable on a per-user basis, add the line to the .bashrc or any other configuration file which is loaded when the user logs in.

Uninstall Java #

You can uninstall Java like any other package installed with apt.

For example, to uninstall the default-jdk package simply run:

sudo apt remove default-jdk

Conclusion #

The most recent LTS model of OpenJDK is accessible within the default Raspbian repositories, and the set up is an easy and easy activity.

When you’ve got any questions, be happy to depart a remark.

Copy link
Powered by Social Snap