Step-by-Step Guide for Installing Oracle JDK and OpenJDK on Raspberry Pi

This article provides a step-by-step guide for installing both Oracle JDK and OpenJDK on Raspberry Pi. It covers everything from updating your system, choosing the right Java version, and setting up e …


Updated August 1, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


This article provides a step-by-step guide for installing both Oracle JDK and OpenJDK on Raspberry Pi. It covers everything from updating your system, choosing the right Java version, and setting up environment variables to verify installation.

Installing Java on Raspberry Pi

Java is a popular programming language used in various fields such as web development, mobile app development, and artificial intelligence. In this article, we will learn how to install Oracle JDK and OpenJDK on Raspberry Pi. Before proceeding, make sure you have the latest version of Raspberry Pi OS installed and updated.

Update your system

The first step is to update your system to ensure all packages are up-to-date. Open a terminal window and run the following commands:

sudo apt update && sudo apt upgrade -y

This command will fetch the latest package information from the repositories and install any available updates.

Choose between Oracle JDK or OpenJDK

There are two popular Java Development Kits (JDKs) available for Raspberry Pi: Oracle JDK and OpenJDK. Oracle JDK is proprietary and requires a subscription, while OpenJDK is open-source and free to use.

Installing Oracle JDK

To install Oracle JDK on your Raspberry Pi, you will need to add the official Oracle APT repository to your system. To do this, run the following commands:

sudo apt install curl
curl -L https://www.oracle.com/java/technologies/javase-jdk17-downloads.html --output ~/Downloads/oracle-jdk.html

This will download the Oracle JDK download page and save it as oracle-jdk.html in your ~/Downloads directory. Open this file using a text editor, navigate to the Linux ARM 32-bit download link, and copy the URL. Then run:

sudo apt-get install apt-transport-https ca-certificates gnupg
echo "deb https://download.oracle.com/otn-pub/java/jdk/17+35/e4175a093d4f146d3868c31ee88280dd90cac9/jdk-17_linux-armv6hf_bin.deb jdk17 main" | sudo tee /etc/apt/sources.list.d/oracle-jdk.list
wget --no-check-certificate -O /tmp/oracle-jdk.key https://download.oracle.com/otn-pub/java/jdk/17+35/e4175a093d4f146d3868c31ee88280dd90cac9/jdk-17_linux-armv6hf_bin.deb
sudo apt-key add /tmp/oracle-jdk.key

Replace e4175a093d4f146d3868c31ee88280dd90cac9 with the latest hash value from the download link you copied. Next, run:

sudo apt update && sudo apt install oracle-java17-installer -y

This will install Oracle JDK 17 on your Raspberry Pi.

Installing OpenJDK

OpenJDK is the open-source alternative to Oracle JDK and can be installed using the following commands:

sudo apt update && sudo apt install default-jdk -y

This command will install the latest version of OpenJDK available in the Raspberry Pi repositories.

Set environment variables

To ensure Java is accessible from any directory, set the JAVA_HOME environment variable by adding the following line to your .bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-17-oracle # Replace 17 with the version you installed

Then, add the bin directory of Java to your PATH:

export PATH=$JAVA_HOME/bin:$PATH

Save the changes and run:

source ~/.bashrc

To verify that Java is installed correctly, run:

java -version

You should see the version of Java you just installed.

Conclusion

In this article, we learned how to install both Oracle JDK and OpenJDK on Raspberry Pi. We updated our system, chose the right Java version, and set environment variables to ensure Java is accessible from any directory. After installation, we verified that Java was working by running java -version. With Java installed on your Raspberry Pi, you can now develop and run Java applications.