Updating Java on Raspberry Pi

I couldn’t log in anymore 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 aren’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"

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

28 thoughts on “Updating Java on Raspberry Pi”

  1. Wow, thanks so much – upgrading my Unifi-pi broke it with very cryptic messages. This article fixed it, about three minutes shy of a painful reinstall.

    The fix was:
    sudo apt-get install openjdk-8-jre-headless -y

    Here are the errors in order to help search engines:

    [2019-12-20 13:23:13,094] ERROR system – unable to exec
    java.io.IOException: Cannot run program “bin/mongod” (in directory “/usr/lib/unifi”): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

    [2019-12-20T13:27:20,479] ERROR system – [exec] error, rc=141, cmdline=[/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java, -Dfile.encoding=UTF-8, -Djava.awt.headless=true, -Dapple.awt.UIElement=true, -Xmx1024M, -XX:+ExitOnOutOfMemoryError, -XX:+CrashOnOutOfMemoryError, -XX:ErrorFile=/usr/lib/unifi/logs/hs_err_pid%p.log, -jar, /usr/lib/unifi/lib/ace.jar, start]

    I also had the NO_PUBKEY errors mentioned above.

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

    pi@raspberrypi:~ $ 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.

  3. The Webupd8 team no longer hosts the Java updates. Any idea how to get it loaded into the Pis now?

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

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

    pi@raspberrypi:~ $ 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.

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

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

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

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

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

    Took couple of min until the controller was up again!

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

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

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

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


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