Java is a well-known platform for creating and running software applications. How to Install Java on Raspberry Pi? Java is widely used to power web-based applications.
How to Install Java on Raspberry Pi with the aid of this guide. The article also explains how to provide the default JAVA HOME path environment variable and set the default Java version.
- Two, three, or four Raspberry Pis
- An individual with sudo rights
- Access to a command line or terminal
Note about Raspberry Pi and Java
Go to the next section if you are already familiar with Java and Raspberry Pi.
There are two primary Java versions:
A Java environment that is open-source and covered by the GNU General Public License is called OpenJDK.
Oracle Java is a for-profit service that offers licensing and support choices.
You might come across many acronyms while exploring different Java versions:
- Standard Edition (SE) (usually for Oracle Java)
- Java Runtime Environment (JRE) (for running Java applications)
- The Java Development Kit (JDK) (for writing and running Java applications)
- Lengthy-Term Support (major software versions intended for long-term use)
Java installation for the Raspberry Pi
Raspbian is the operating system that comes preinstalled on Raspberry Pi. Because Raspbian is based on Debian, installing Java with terminal commands will use the apt package management.
Installing every package from the default Raspbian software repositories is advised. Numerous packages are incompatible due to the ARM-based system architecture of the Raspberry Pi.
1: Install OpenJDK Java 11 on Raspberry Pi
How to Install Java on Raspberry Pi? OpenJDK is available in the standard Raspbian repositories in a fully updated and functional state.
1: Type the following in a terminal window:
sudo apt update
sudo apt install default-jdk
To use the most recent software, use the first command to update your package repositories. Java is installed using the second command.
2: When prompted, enter Y and press Enter to let the procedure finish.
3: By examining the software version, you can confirm the installation:
version of Java
The software version will be shown by the system. It ought to show something like this:
Depending on the most recent Java version that is accessible, your version may change.
2: On a Raspberry Pi, install OpenJDK Java 8
1: In a terminal window, type the following to install OpenJDK 8:
apt update with sudo
install OpenJDK-8-jdk with sudo apt
The list of software packages in your repositories is updated by the first command. The next command sets up Java OpenJDK version 8.
2: Type Y and press Enter to confirm if necessary and let the procedure finish.
3: Use the following to confirm the installation:
version of Java
The software version will be shown by the system. It ought to show something like this:
3: Make the Java version the default (Optional)
Your default version will most likely be the most recent version if you installed both OpenJDK 8 and 11 (OpenJDK 11). The default Java version on your machine can be verified using:
version of Java
1: To change the Java version manually, start by executing the following command:
update-alternatives sudo java configuration
All installed Java instances on your Raspberry Pi system will be listed in the output.
2: There will be a * next to the default version. To make a different version of Java the system default, enter a selection number and press Enter.
Refer to the example below for more information:
4: Environment variable JAVA HOME Path should be set (Optional)
How to Install Java on Raspberry Pi? You can set the JAVA HOME path environment variable after setting the default Java version for your Raspberry Pi.
1: Start by determining where your default Java instance is located:
update-alternatives sudo java configuration
Generally speaking, the default locations on any Raspberry Pi system are:
/usr/lib/jvm/java-11-openjdk-armhf/bin/java is the OpenJDK 11 path.
/usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java is the OpenJDK 8 path.
2: Edit the /etc/environment file after that:
nano /etc/environment with sudo
3: Include the following in the document:
JAVA HOME="path of your default version of java"
For OpenJDK 8, as an illustration, you should type:
JAVA HOME="/usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java"
4: After saving the document, close the text editor.
5: Reboot your computer now to make the modifications effective:
sudo restart
6: Run the upcoming command to confirm the adjustments:
reflect $JAVA HOME
The JAVA HOME location specified in the /etc/environment file should be returned in the output.
5: Remove Java from the Raspberry Pi.
How to Install Java on Raspberry Pi? You used the apt package manager to install Java 8 and/or Java 11 by following this tutorial. Using apt, you may also remove Java from the Raspberry Pi.
Run the following command on your Raspberry Pi device to remove Java 8:
sudo apt remove openjdk-8-jdk
Wait for the procedure to finish and then press Y and Enter to confirm.
Run the following command to remove Java 11 on your Raspberry Pi computer:
uninstall default-jdk with sudo apt
Wait for the procedure to finish and then press Y and Enter to confirm.
Conclusion
The instructions on How to Install Java on Raspberry Pi Java 8 and Java 11 on a Raspberry Pi were provided in this tutorial. On your Raspberry Pi, OpenJDK 11 or OpenJDK 8 should now be operationally installed.
The post also instructed you on how to define the JAVA HOME path environment variable and specify the default Java version in use. Visit our tips on how to set environment variables in MacOS or Linux for other tutorials that are similar to this one.