Java is one of the most widely used programming languages for developing various applications and systems.
Oracle Java and OpenJDK are two alternative Java implementations. OpenJDK is an open-source Java Platform implementation. Oracle Java provides a few extra commercial features, as well as a licence that solely allows for non-commercial use, such as personal or development use.
This tutorial will show you How to install Java (OpenJDK) on a Raspberry Pi running the newest Raspbian OS.
Java Runtime Environment (JRE) and Java Development Kit are both included in the regular Raspbian repository (JDK). The Java virtual machine (JVM), classes, and binaries that make it possible to run Java programmes are all included in JRE. The Java Development Kit (JDK) includes the Java Runtime Environment (JRE), as well as the development and debugging tools and libraries required to create Java programmes.
If you're not sure which Java package to install, the default OpenJDK (JDK 11) version is a good place to start. Some Java-based apps may require a specific version of Java, so check the programme documentation for more information.
Installing Java 11 on a Raspberry Pi is a simple process.
OpenJDK 11 is the default Java development and runtime on the newest Raspbian OS, which is based on Debian 10, Buster.
To install the OpenJDK 11 JDK on your Raspberry Pi, do the following commands:
sudo apt update
sudo apt install default-jdk
Verify that the installation is complete by looking at the Java version:
java -version
This is what the final product should look like:
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 concludes our discussion. You have now successfully installed Java on your Raspberry Pi and are ready to use it.
How to Install Java 8 on a Raspberry Pi
The previous Java LTS version 8, which was released in 2008, is still maintained and widely used. Install Java 8 if your programme requires it by typing:
Print the Java version to confirm the installation:sudo apt update
sudo apt install openjdk-8-jdk
java -version
This is what the final product should look like:
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)
Configure the Default Version
If your Pi has numerous Java versions loaded, use the java -version command to see which one is the default:
java -version
Use the update-alternatives utility to change the default version:
sudo update-alternatives --config java
The following is an example of the output:
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:
A list of all installed Java versions will be displayed. Press Enter after entering the number of the version you wish to be the default.
Environment Variable JAVA_HOME
Some Java programmes utilise the JAVA_HOME environment variable to determine the location of the Java installation.
To identify where Java is installed and adjust the JAVA HOME environment variable, use the update-alternatives command:
sudo update-alternatives --config java
Use the update-alternatives utility to change the default version:
sudo update-alternatives --config java
The following is an example of the output:
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
Open the /etc/environment file after you've determined the path to the Java installation:
sudo nano /etc/environment
Add the following line at the end of the file if you wish to set JAVA_HOME to OpenJDK 11:
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-armhf"
You may either log out and back in or execute the source command to apply the modifications to your current shell:
source /etc/environment
Type: to see if the JAVA_HOME setting is set.
echo $JAVA_HOME
The path to the Java 11 binary should be as follows:
/usr/lib/jvm/java-11-openjdk-armhf
/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 from Raspberry Pi
apt
, may be uninstalled.sudo apt remove default-jdk
Posts You May like:
- The Raspberry Pi Foundation has Announced the Availability of a New Method for Installing an Operating System
- The 64-bit Raspberry Pi OS is now available for users of the Raspberry Pi 3 and Pi 4
- StackyPi - Based on Raspberry Pi RP2040 MCU
- The RP2040 StackyPi is a Pi Zero-sized Raspberry Pi that supports HATs.
- How to Block Ads with Pi-hole on a Raspberry Pi Zero 2 W
- Uninterruptible Power Supply UPS HAT For Raspberry Pi
- A hidden speed boost and a 64-bit option are included in the new #RaspberryPi #OS
- Using the On-Board Bluetooth on the Raspberry Pi 4 for Communication
- #ArduinoIDE 2.0 Release Candidate (RC)
- Armbian Linux on the Raspberry Pi 4: A First Look
- NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi
- What Type of LoRa Modules are Available?
- Introducing The VisionFive V1 is a RISC-V Based Raspberry Pi Replacement - Available Soon
- Raspberry Pi Zero 2 W Overclocking - Boost Up To 1.2GHz, or even 1.4GHz
- The Arduino UNO Mini Limited Edition is Now Available
- Scan QR Codes with Raspberry Pi Pico
- Create Barcodes with Pure Python
- The New Version of Raspberry Pi OS, Debian "Bullseye" is Now Available.
- The Raspberry Pi Zero 2 W Arrives Six Years After The First Pi Zero
- Raspberry Pi 4 Has Been Given Vulkan 1.1 Compliance by Khronos
- The Raspberry Pi Build HAT - Complete Guide
- Raspberry Pi Officialy Announced Build HAT For Raspberry Pi
- Installing Android on a Raspberry Pi 4 with Google Play Store
- Pop OS Linux is Coming to Raspberry Pi and Other ARM Devices Soon
- How to Immediately Upgrade to Windows 11
- A Secret Update for the Raspberry Pi 4 8GB
- Rasspberry Pi Introduces a New Documentation Hub
- Quick start with ESP8266 based Pico WiFi HAT
- Capture local Real-Time Air Quality Data with Raspberry Pi Pico
- Debian 10 Buster to Debian 11 Bullseye Upgrade
- How to Use CIFS to Mount a Windows Share on Linux
- Both 1.54 and 2.7 inch Raspberry Pi E Paper HATs are available.
- How do I enable Desktop to Raspberry Pi 4 2GB
- Ubuntu 22.04 to Bring the Desktop to Raspberry Pi 4 2GB Users
- How to Use BerryBoot to Dual-Boot a Raspberry Pi
- StackyPi - Based on Raspberry Pi RP2040 Microcontroller
- Enhance your Raspberry Pi with Audio - Audio Codec HAT
- Ubuntu 22.04 to Bring the Desktop to Raspberry Pi 4 2GB Users
- Audio Codec HAT adds sound to your Raspberry Pi
- The KiCad Project Announced Version 6.0.0. #KiCad @kicad_pcb
- LoRa HAT is Finally Out! Supports 915MHz | 868MHz | 433MHz
- How to Block Ads with Pi-hole on a Raspberry Pi Zero 2 W
- Uninterruptible Power Supply UPS HAT For Raspberry Pi
- A hidden speed boost and a 64-bit option are included in the new #RaspberryPi #OS
- Using the On-Board Bluetooth on the Raspberry Pi 4 for Communication
- #ArduinoIDE 2.0 Release Candidate (RC)
- Armbian Linux on the Raspberry Pi 4: A First Look
- NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi
- The Raspberry Pi Foundation has Announced the Availability of a New Method for Installing an Operating System
- The 64-bit Raspberry Pi OS is now available for users of the Raspberry Pi 3 and Pi 4
- StackyPi - Based on Raspberry Pi RP2040 MCU
- The RP2040 StackyPi is a Pi Zero-sized Raspberry Pi that supports HATs.
- How to Block Ads with Pi-hole on a Raspberry Pi Zero 2 W
- Uninterruptible Power Supply UPS HAT For Raspberry Pi
- A hidden speed boost and a 64-bit option are included in the new #RaspberryPi #OS
- Using the On-Board Bluetooth on the Raspberry Pi 4 for Communication
- #ArduinoIDE 2.0 Release Candidate (RC)
- Armbian Linux on the Raspberry Pi 4: A First Look
- NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi
- What Type of LoRa Modules are Available?
- Introducing The VisionFive V1 is a RISC-V Based Raspberry Pi Replacement - Available Soon
- Raspberry Pi Zero 2 W Overclocking - Boost Up To 1.2GHz, or even 1.4GHz
- The Arduino UNO Mini Limited Edition is Now Available
- Scan QR Codes with Raspberry Pi Pico
- Create Barcodes with Pure Python
- The New Version of Raspberry Pi OS, Debian "Bullseye" is Now Available.
- The Raspberry Pi Zero 2 W Arrives Six Years After The First Pi Zero
- Raspberry Pi 4 Has Been Given Vulkan 1.1 Compliance by Khronos
- The Raspberry Pi Build HAT - Complete Guide
- Raspberry Pi Officialy Announced Build HAT For Raspberry Pi
- Installing Android on a Raspberry Pi 4 with Google Play Store
- Pop OS Linux is Coming to Raspberry Pi and Other ARM Devices Soon
- How to Immediately Upgrade to Windows 11
- A Secret Update for the Raspberry Pi 4 8GB
- Rasspberry Pi Introduces a New Documentation Hub
- Quick start with ESP8266 based Pico WiFi HAT
- Capture local Real-Time Air Quality Data with Raspberry Pi Pico
- Debian 10 Buster to Debian 11 Bullseye Upgrade
- How to Use CIFS to Mount a Windows Share on Linux
- Both 1.54 and 2.7 inch Raspberry Pi E Paper HATs are available.
- How do I enable Desktop to Raspberry Pi 4 2GB
- Ubuntu 22.04 to Bring the Desktop to Raspberry Pi 4 2GB Users
- How to Use BerryBoot to Dual-Boot a Raspberry Pi
- StackyPi - Based on Raspberry Pi RP2040 Microcontroller
- Enhance your Raspberry Pi with Audio - Audio Codec HAT
- Ubuntu 22.04 to Bring the Desktop to Raspberry Pi 4 2GB Users
- Audio Codec HAT adds sound to your Raspberry Pi
- The KiCad Project Announced Version 6.0.0. #KiCad @kicad_pcb
- LoRa HAT is Finally Out! Supports 915MHz | 868MHz | 433MHz
- How to Block Ads with Pi-hole on a Raspberry Pi Zero 2 W
- Uninterruptible Power Supply UPS HAT For Raspberry Pi
- A hidden speed boost and a 64-bit option are included in the new #RaspberryPi #OS
- Using the On-Board Bluetooth on the Raspberry Pi 4 for Communication
- #ArduinoIDE 2.0 Release Candidate (RC)
- Armbian Linux on the Raspberry Pi 4: A First Look
- NeoPixel Christmas Tree Lights Controlled by a Raspberry Pi