Updating Java on Raspberry Pi

I couldn’t log in any more on my Unifi Controller after updating the controller on my Raspberry Pi to version 5.10.12. All I got was a blank screen 🙁

After some digging around I noticed that Java needed to be updated. Rasbian is shipped with an outdated version of Java and for the Unifi Controller we need at least version 1.8.0_201. So in this article I am going to explain how you can update the Raspberry Pi Java version.

Updating Java

We are going to update Java on the PI. The problem is that the latest versions of Java isn’t available in the default repositories for Raspbian. So we need to add the correct repository manually to update Java.

Login to your PI with Putty or your preferred CLI (command line interface) tool. First remove the OpenJDK:

sudo apt-get purge openjdk*

Add a digital key so we can authorize the repository

sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com EEA14886

Add the packet source

sudo vim /etc/apt/sources.list

Add the repository

deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main

Install the latest version of Java 8

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

Remove the old Java version

sudo apt-get purge openjdk*
sudo apt-get purge java7*
sudo apt-get autoremove

Check if we have the latest version of Java:

java -version
#java version "1.8.0_201"

You Java Version on your Raspberry Pi should now be updated to the latest version. If you have the Unifi Controller running on it, all you need to do is reboot the Pi (sudo reboot).

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

27 thoughts on “Updating Java on Raspberry Pi”

  1. I’m trying to upgrade my Unifi Controller and noticed Java is out of date, so following the instructions on this page. Unfortunately, I’m receiving the following message. Any suggestion?

    [email protected]:~ $ sudo apt-get update
    Hit:1 http://raspbian.raspberrypi.org/raspbian stretch InRelease
    Get:2 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease [15.5 kB]
    Hit:3 http://archive.raspberrypi.org/debian stretch InRelease
    Hit:4 http://giteduberger.fr rpimonitor/ InRelease
    Ign:2 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease
    Get:5 https://dl.ubnt.com/unifi/debian stable InRelease [3,024 B]
    Fetched 18.5 kB in 2s (7,816 B/s)
    Reading package lists… Done
    W: GPG error: http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY C2518248EEA14886
    W: The repository ‘http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease’ is not signed.
    N: Data from such a repository can’t be authenticated and is therefore potentially dangerous to use.
    N: See apt-secure(8) manpage for repository creation and user configuration details.

  2. This doesn’t seem to work anymore –
    E: Unable to locate package oracle-java8-installer

    I take it there is some other location to get this package?

  3. I love your site, it is so informative for someone like me who is installing their first Ubiquiti UniFis. Thank you!
    I am having an issue when trying to follow the above directions. I set everything up according to your getting started in 5 minutes guide first. Now, I get this when I try to update java:

    [email protected]:~ $ sudo apt-get install oracle-java8-installer
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    oracle-java8-installer : Depends: java-common (>= 0.24) but it is not installable
    Recommends: gsfonts-x11 but it is not installable
    Recommends: oracle-java8-set-default but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    Any help would be appreciated so much. Thanks again.

  4. Anybody who can help me
    I upgrade Unifi from 5.9.29 to 5.10.19 on a raspberry pi
    My java version is:
    java version “1.8.0_201”

    and when I go to the Unifi URL https://xx.xx.xx.xx:8443/

    I got the message “this site can’t be reached”

    I followed the advise on this site but not succelfull

    and on the steps of Alex (MARCH 10, 2019 AT 6:20 PM)
    I get an error sed: -e expression #1, char 1: unknown command: `“’

    Anybody can help me

    • Jack, I tried the same instructions of Alex (MARCH 10, 2019 AT 6:20 PM) and got the same error. That is due to the formatting on this web page. On the command line, change the quotes to the standard single quote ( ‘ ). The error then will be gone. In my case I then get the next error:
      sed: can’t read /etc/default/unifi: No such file or directory.

      Still plodding along trying to find a solution 🙂

  5. Hi,

    I did as in the guide, but Oracle java fails to work:
    java -version
    Error occurred during initialization of VM
    java/lang/ClassNotFoundException: error in opening JAR file /usr/lib/jvm/java-8-oracle/jre/lib/rt.jar

  6. Thank you!

    I upgraded from 5.9.29 to 5.10.19 and had some issues with the Java version. I don’t know why or what this command does, but this comands helped me.

    sudo -i
    service unifi stop
    apt purge oracle-java8-jdk -y
    sed -i 's/^JAVA_HOME/#JAVA_HOME/' /etc/default/unifi
    echo "JAVA_HOME='$( readlink -f '$( which java )" | sed "s:bin/.*$::" )"" >> /etc/default/unifi
    service unifi start

  7. HI. When I tried this it failed for me. I had downloaded the latest version of raspian with desktop and wrote new sd card.

    I had to fetch dirmngr — sudo apt-get install dirmmgr

    After that everything worked a charm.

  8. Thanks! Followed the guide (but did use nano editor instead) work like a charm.

    Took couple of min until the controller was up again!

  9. Why do not use the OpenJDK package? I installed OpenJDK instead of Oracle java and everything works well. It is much simpler than adding a PPA and I prefer to use official repository.

  10. Thank Ruud, this definitely works out.
    @Lawrence, please install vim first using the command “apt-get install vim”.
    If that gives an error, which happened with my, please clean the cache of the repo:
    sudo apt-get update
    sudo apt-get install vim-runtime
    sudo apt-get install vim

  11. thank you sir!

    i upgraded from 5.9.x to 5.10.17 and was wondering why it wouldnt start. followed this java update guide and back up and running now

  12. Hi Ruud,
    First of all thanks for enlightening all of us with your bits of knowledge.
    When going through your instructions the third line (sudo vim /etc/apt/sources.list) returns an error (sudo: vim: opdracht niet gevonden).
    How to proceed from here?

    Thanks!

  13. Thank you. I have Unifi Controller and OpenHabian running on my RPi, and couldn’t use Zulu Embedded Java as recommended by OpenHabian as it wasn’t yet on level 201. Using Oracle Java package allowed both two services run fine.

Leave a Comment