Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to install the latest java version in Raspbian (Stretch)


The default version of java provided in the latest raspbian images are outdated, so we are going to install from the ppa:webupd8team/java repository instead. Please note that add-apt-repository ppa:webupd8team/java will not work, so we will need to add the repository manually.


  1. Create the gpg key file and paste the following lines of text below
nano key.txt
Version: SKS 1.1.5
Comment: Hostname:

  1. Add the gpg key
sudo apt-key add key.txt
  1. Add the repository to /etc/apt/sources.list.d/ and perform an update
echo "deb xenial main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src xenial main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-get update
  1. Install Java 8 SDK
sudo apt-get install oracle-java8-installer 
  1. Verify that we have successfully installed java
pi@raspberrypi:~# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode)

Switching between versions

If you have multiple jvms installed and you want to switch back to a specific version of java you can do the following:

Option 1

  1. List the available versions in your system
update-java-alternatives -l
  1. Copy the key of the first column of the result of your target version
java-8-oracle                  1081       /usr/lib/jvm/java-8-oracle
  1. Execute the set command using the previously copied key
update-java-alternatives -s java-8-oracle

Option 2

sudo apt-get install oracle-java8-set-default

More details here

Copy link

I went through the hoops of installing the Oracle JRE, but the Unifi controller kept using the 'wrong' version of Java, so I too installed the OpenJDK version;

sudo apt-get install openjdk-8-jre-headless -y

and the controller restarted without any issues.

Worked for me. Thanks!

Copy link

pi@pi:~ $ sudo apt-get install oracle-java8-installer
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package oracle-java8-installer is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'oracle-java8-installer' has no installation candidate

I'm getting the same error on a Raspberry Pi 2B running Raspbian GNU/Linux 10 \n \l

Any ideas?

Copy link

ribasco commented Sep 25, 2019

The PPA for oracle jdk 8 has been discontinued. I suggest you install the openjdk version instead.

Copy link

The PPA for oracle jdk 8 has been discontinued. I suggest you install the openjdk version instead.

root@pi-hole:/home/pi# java -version
Error occurred during initialization of VM
Server VM is only supported on ARMv7+ VFP

Looks like I will re-install my Pi with Raspbian 9 instead of 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment