Skip to content

Instantly share code, notes, and snippets.

@davecoutts
Last active September 18, 2023 19:07
Star You must be signed in to star a gist
Embed
What would you like to do?
Install Ubiquiti Unifi Controller on Ubuntu 20.04
# Install Ubiquiti Unifi Controller on Ubuntu 20.04.
# As tested on a fresh install of ubuntu-20.04.1-live-server, August 22nd 2020.
# Thanks to https://gist.github.com/tmuncks for posting the updated install steps.
sudo apt update
sudo apt install --yes 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
sudo apt update
sudo apt install --yes openjdk-8-jre-headless unifi
sudo apt clean
sudo systemctl status --no-pager --full mongodb.service unifi.service
# Now log into https://unifi_controller_hostname:8443/
## ------------------------------------------------------------------------------------------------------------------------
## Previous install steps from when unifi still required mongodb-server <= 3.4.
## unifi has since been updated to work with mongodb-server 3.6. Which is available from the Ubuntu 20.04 main repository.
## ------------------------------------------------------------------------------------------------------------------------
#
# sudo apt install --yes 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 apt-key adv --keyserver keyserver.ubuntu.com --recv 06E85760C0A52C50
# wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | sudo apt-key add -
# echo 'deb https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
# sudo apt-mark hold openjdk-11-*
# sudo apt update
# # mongodb 3.4 dependency
# wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.3_amd64.deb -P /tmp
# sudo apt install --yes /tmp/libssl1.0.0_1.0.2n-1ubuntu5.3_amd64.deb
# rm /tmp/libssl1.0.0_1.0.2n-1ubuntu5.3_amd64.deb
# sudo apt install --yes mongodb-org
# sudo apt install --yes unifi
@desdougan
Copy link

I followed this and found I also had to install openjdk-8-jdk to get it running. Thanks for putting this together - it helped greatly.

@Starkstromkonsument
Copy link

Hi, thank you for your feedback. It turned out to be my own fault, because I had set the parameter unifi.https.port=443 without granting the permission to bind to a privileged port. The IOExceptions are still there but unifi works fine anyway ...

@USMA56795
Copy link

How do you get MongoDB 3.6.x installed on Ubuntu 20.x? MongoDB < 4.x is EOL. Is it just a matter of adding the 3.6 repo?

@davecoutts
Copy link
Author

Hi @USMA56795
If you run apt install --dry-run mongodb-server it will simulate installing mongodb-server and show you the version that would have been installed.
You should find that mongodb-server version 3.6.9 is the current default version for Ubuntu 20.04.3 LTS.

Equally you can check package versions and dependencies with the apt-cache command, as per the examples below.
You will see that the current unifi package has a mongodb-server version dependency of >= 2.4.10 << 4.0.0

uni01:~$ lsb_release -d
Description: Ubuntu 20.04.3 LTS

uni01:~$ apt-cache policy mongodb-server
mongodb-server:
  Installed: 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3
  Candidate: 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3
  Version table:
 *** 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3 500
        500 http://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 http://gb.archive.ubuntu.com/ubuntu focal-security/universe amd64 Packages
        100 /var/lib/dpkg/status
     1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5 500
        500 http://gb.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

uni01:~$ apt-cache show unifi
Package: unifi
Version: 6.4.54-16067-1
Architecture: all
Depends: binutils, coreutils, adduser, libcap2, curl,
 mongodb-server (>= 2.4.10) | mongodb-10gen (>= 2.4.14) | mongodb-org-server (>= 2.6.0),
 mongodb-server (<< 1:4.0.0) | mongodb-10gen (<< 4.0.0) | mongodb-org-server (<< 4.0.0),
 java8-runtime-headless | java11-runtime-headless, jsvc (>=1.0.8), logrotate
Pre-Depends: debconf (>= 0.5) | debconf-2.0
Conflicts: unifi-controller
Provides: unifi-controller
Replaces: unifi-controller
Installed-Size: 225095

@USMA56795
Copy link

Thanks so much for the detailed reply @davecoutts. This is exactly the help I needed.

@userthirtytwo
Copy link

userthirtytwo commented Nov 10, 2021

Thanks for this! Also- how can I tell which version (unifi version) installed via CLI? (I cant access the webui yet since I need to wait for a pause in production)

@davecoutts
Copy link
Author

davecoutts commented Nov 10, 2021

Hi @userthirtytwo

Running either of the commands below on the server unifi is installed on should give you the version information.

Version reported by the installed unifi package meta data.

uni01:~$ dpkg -s unifi | grep -i version
Version: 6.4.54-16067-1

Version reported by the running unifi web server API interface.

uni01:~$ curl -ks https://localhost:8443/status | python3 -m json.tool
{
    "meta": {
        "rc": "ok",
        "up": true,
        "server_version": "6.4.54",
        "uuid": "53023d6c-06fd-4ef3-86a5-fad7dafcf280"
    },
    "data": []
}

@emilholic
Copy link

thank you it works.

@kagawa-sagawa
Copy link

Any help in linking digital ocean with unifi

@helmist
Copy link

helmist commented Mar 9, 2022

For those wanting to allow all the ports used by the controller from UI's Documentation, the below adds every port except for the ports used by AP-EDU broadcasting. you might also want to ad an explicit ssh-over-tcp rule with sudo ufw allow 22/tcp.

sudo ufw enable
sudo ufw allow 3478/udp
sudo ufw allow 5514/udp
sudo ufw allow 8080/tcp
sudo ufw allow 8443/tcp
sudo ufw allow 8880/tcp
sudo ufw allow 8843/tcp
sudo ufw allow 6789/tcp
sudo ufw allow 27117/tcp
sudo ufw allow 10001/udp
sudo ufw allow 1900/udp
sudo service unifi restart

@rakhbari
Copy link

For me, this is all that was needed on a clean 20.04 install:

sudo apt-get update
sudo apt-get install --yes ca-certificates apt-transport-https wget

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

sudo apt update
sudo apt install --yes openjdk-8-jre-headless unifi

Jupp thanks man. This worked flawlessly.

@RocketLR Thanks for these simple instructions. It worked perfectly for me as well. Cheers! 👍

@lamixer
Copy link

lamixer commented Jul 20, 2022

Yes, thank you for this! I love Debian, but I wasted over an hour fighting with Debian 11 and mongodb versions and other apt problems; I lost. This just works, I installed at Unifi version 7.1.66. I spun up an Ubuntu 20.04 Linux container in Proxmox, updated and (since I was logged in as root, removed sudo, and I like to type Y so):

apt-get install ca-certificates apt-transport-https wget

echo 'deb https://www.ui.com/downloads/unifi/debian stable ubiquiti' | tee /etc/apt/sources.list.d/100-ubnt-unifi.list

wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg

apt update

apt install openjdk-8-jre-headless unifi

Thanks Dave and everyone.

@davecoutts
Copy link
Author

davecoutts commented Jul 21, 2022

@lamixer you are welcome.

I feel your dependency hell pain.

The software stack versions for unifi are starting to become a problem with newer operating systems.
The issues I have found are,

  • mongodb has been dropped from the stable Debian and Ubuntu repositories.
  • unifi requires mongodb 3.x, which requires libssl1.1, which Ubuntu 22.04 depreciated in favor of libssl3.
  • Debian stable has dropped openjdk 8. unifi dependencies states it can use openjdk 11. Yet unifi fails to run without modifying the openjdk 11 installation.

I do hope Ubiquity is planning to update unifi to make it easier to install on current Linux operating systems.

If you would like to try Debian again I found that the following install steps worked on Debian 10 and 11.

# unifi 7 Debian 10 & 11 installation.
#
# https://gist.github.com/davecoutts
#
# mongodb installed from www.mongodb.org 

sudo apt update
sudo apt install --yes gnupg wget haveged

# unifi repository

wget -qO- https://dl.ui.com/unifi/unifi-repo.gpg \
| sudo tee /usr/share/keyrings/unifi-archive-keyring.gpg > /dev/null

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/unifi-archive-keyring.gpg] \
https://www.ui.com/downloads/unifi/debian stable ubiquiti" \
| sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list > /dev/null

# mongodb-org repository

wget -qO- https://www.mongodb.org/static/pgp/server-3.6.asc \
| sudo gpg --dearmor -o /usr/share/keyrings/mongodb-org-server-3.6-archive-keyring.gpg > /dev/null

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-org-server-3.6-archive-keyring.gpg] \
https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/3.6 multiverse" \
| sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list > /dev/null

# set JAVA_HOME environment variable for the unifi service

sudo mkdir /etc/systemd/system/unifi.service.d

printf "[Service]\nEnvironment=\"JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64\"\n" \
| sudo tee /etc/systemd/system/unifi.service.d/10-override.conf > /dev/null

# Install openjdk 11

sudo apt update
sudo apt install --yes openjdk-11-jre-headless

# Workaround issue where jsvc expects to find libjvm.so at lib/amd64/server/libjvm.so
sudo ln -s /usr/lib/jvm/java-11-openjdk-amd64/lib/ /usr/lib/jvm/java-11-openjdk-amd64/lib/amd64

# Install and enable mongodb 3.6

sudo apt install --yes mongodb-org-server

sudo systemctl enable mongod.service
sudo systemctl start mongod.service

# Install unifi

sudo apt install --yes unifi
sudo apt clean

# Post installation checks

systemctl status --no-pager --full mongod.service unifi.service

wget --no-check-certificate -qO- https://localhost:8443/status | python3 -m json.tool

sudo journalctl --no-pager --unit unifi.service

sudo cat /usr/lib/unifi/logs/server.log

sudo cat /usr/lib/unifi/logs/mongod.log

@lukehoersten
Copy link

All - thank you for all the comments and discussion here.

With this post and some extra work, I was able to get Unifi working on Ubuntu Jammy on a Raspberry Pi arm64. Especially thanks to @dbosk for pointing to the armhf Unifi repo.

I wrote up a description and ansible role for those wanting a script and explainer of what worked for me.

@thien154
Copy link

what is default admin username and password of mongodb ?

@gmhabchi
Copy link

Off the back of @ficematt using https://glennr.nl/s/unifi-network-controller make the process alot easier 👍

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