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:

Add a digital key so we can authorize the repository

Add the packet source

Add the repository

Install the latest version of Java 8

Remove the old Java version

Check if we have the latest version of Java:

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.

16 thoughts on “Updating Java on Raspberry Pi”

  1. 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.

  2. 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

  3. 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

  4. 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

  5. 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.

  6. 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.

  7. 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

  8. 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

  9. 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!

  10. 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