Just recently, I’ve got a new Raspberry Pi 3 Model B and started experimenting with it. I’ve installed the latest Raspbian (Jessie Lite) on it because it’s the officially supported operating system and more importantly, it works out-of-the-box.
I was thinking of writing some applications for it so I decided to install Java since it’s the programming language I’m most familiar with.
There are basically two options available for Raspbian — you can either use OpenJDK or Oracle JDK. There are some limitations of OpenJDK for ARM systems which make it slower so I’ve decided to stick with Oracle JDK.
You can install oracle-java8-jdk package from the official Raspbian repositories but it only provides an old version of Java (8u65). If you want to use the latest version, you need to download the JDK directly from the Oracle’s website. Since Raspberry Pi is powered by ARM processor and Raspbian is a 32-bit OS, choose the Linux ARM 32 Hard Float ABI version.
When you download the right package, unpack it into /usr/java directory:
sudo mkdir /usr/java
cd /usr/java
sudo tar xf ~/jdk-8u111-linux-arm32-vfp-hflt.tar.gz
You can then create symbolic links in /usr/bin folder (so you’ll be able to use java command anywhere) by adding the following alternatives:
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_111/bin/java 1000
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_111/bin/javac 1000
At this point, you should be able to verify that your Java installation works by running the following command:
java -version
It should print something like this:
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) Client VM (build 25.111-b14, mixed mode)
If you see similar output, you have successfully installed Java 8 on Raspberry Pi.