Unifi controller on Debian Buster with Java 11

I was moving my Unifi controller to a new VM and wanted to use Debian Buster which has been the current release for a year now. It seems Ubiquiti's own instructions only mention Jessie and Stretch as of July 2020, which is unfortunate as Jessie LTS is now past the end of its support and is no longer getting any security updates.

It also doesn't help that Debian have dropped MongoDB in recent releases for licensing reasons, and that the Unifi controller requires older versions of MongoDB and Java.

Installing the latest MongoDB version 4 doesn't work, as the unifi .deb requires MongoDB 3. Here's how I got it working without installing truly ancient software.

MongoDB 3

There are some guides that suggest installing 3.4 from Jessie which needs some old libraries, but there's no need - the controller works fine with 3.6. It's not packaged for Buster, but the Stretch version works without any bodging.

echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -

apt update
apt install mongodb-org
systemctl start mongod
systemctl enable mongod


As per the unifi instructions.

apt install ca-certificates apt-transport-https
echo 'deb https://www.ui.com/downloads/unifi/debian stable ubiquiti' | sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list
sudo wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg 
apt update
apt install unifi

This will install a load of dependencies including Java 11, which initially doesn't work. Thankfully there are a couple of simple fixes - although this isn't supported, my controller seems to be working fine with this.

Check to see why it's not starting:

systemctl start Unifi
journalctl -u unifi

Fix Java

The first issue to fix is the JAVA_HOME variable, otherwise you get an error saying "Cannot locate Java Home". This should be relatively safe for any future upgrades:

echo 'JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"' | sudo tee /etc/default/unifi

The Unifi controller still doesn't work though, the log reports: "Cannot find any VM in Java Home". A bit of testing with strace and it seems to be looking for libraries in a directory that's in a different place. Sticking this symlink in seems to resolve it:

ln -s /usr/lib/jvm/java-11-openjdk-amd64/lib/ /usr/lib/jvm/java-11-openjdk-amd64/lib/amd64

It's alive!

Finally, start the controller:

systemctl start unifi
systemctl status unifi
systemctl enable unifi

You should then be able to access the controller on https://whatever:8443 as usual.

I put mine behind nginx with a Let's Encrypt certificate to get rid of the TLS warnings, but that's beyond the scope of this guide.

Contact: site@spod.cx