Home Assistant

How To Install Home Assistant On Ubuntu

So why would you want to run Home Assistant on a full blown Linux distro rather than just a Raspberry Pi? I recently migrated my Home Assistant setup over to Ubuntu for a couple of reasons and i’ll explain why.

Why use linux?

There are several reasons you might want Home Assistant running on Linux. At the time of my first Home Assistant setup I only had an old Raspberry Pi 2 lying around. I built my initial setup on the Pi but shortly after I wanted more power.

I happened to have an old MacBook Pro gathering dust in a draw. I had been on many emotional journeys with this machine in the 10 years of ownership and I didn’t have the heart to throw it in the trash, plus I hate to contribute towards electrical waste. Perhaps its the reason I still use an iPhone SE in 2020!

I decided that this machine would be perfect for my Home Assistant server, it had 8GB of RAM, a Core Duo 2 processor and an SSD drive so would outperform the Pi. Best of all it was not going to cost me anything and at the same time I could do something for the environment. It was a little dented, scratched and beaten up but that didn’t matter because I was planning to hide it in the TV cabinet anyway.

As the only purpose of this machine is to run Home Assistant, I decided to make the machine headless and install Ubuntu server. However this setup guide will work just fine with the standard desktop release too. I am sure it will also work with other versions of Linux so if you are using a different distro, let us know the results in the comments!

Requirements

  • A computer running Ubuntu with internet access setup
  • A nice beverage and some atmospheric music

Prerequisites

Update Linux

As always the first thing to do is make sure Linux is up to date. Open up the terminal, then simply enter the following commands and allow any updates to install.

sudo apt-get update
sudo apt-get upgrade

Install Docker

Docker is a clever little program that allows you to install and run applications within a ‘container.’ All of the dependencies required by the application can be packaged up into the container and are kept separate from the rest of the system. This allows specific versions of libraries and other dependencies to be contained with their application and it prevents version conflicts in the system.

Firstly we need to install some additional packages to prepare for the Docker installation. Simply enter the following command in to the terminal.

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Next we need to add the GPG key for Docker to our system. The purpose of this is for ensuring the validity of the download.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Now we can verify that we have added the key successfully, simply enter the following command.

apt-key fingerprint 0EBFCD88

If the key has been added successfully, this command will return the information about the key.

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) docker@docker.com
sub   rsa4096 2017-02-22 [S]

Next we need to add the Docker repository by entering the following command.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

We are now ready to install docker, so go ahead and enter the following command.

sudo apt-get install docker-ce docker-ce-cli containerd.io

Once Docker has finished installing we need to ensure that it will start when the system boots, so go ahead and enter this command.

systemctl enable docker

Finally we can test that Docker has been successfully installed by running the hello world command.

sudo docker run hello-world

If the installation was successful, you will receive the hello message from Docker.

Hello from Docker! This message shows that your installation appears to be working correctly.

Install Hass.io and Home Assistant

The newer version of Home Assistant runs on its own operating system called Hassio. The following steps will guide you through the installation of Hassio, which will also equip your system with Home Assistant.

Firstly we will need to install some additional packages, so go ahead and enter the following command.

apt-get install apparmor-utils avahi-daemon dbus jq network-manager socat

Now we can install Hass.io and Home Assistant with the following command.

sudo curl -sL "https://raw.githubusercontent.com/Kanga-Who/home-assistant/master/supervised-installer.sh" | bash -s

Configure Home Assistant

Firstly we need to know the IP address of our new Home Assistant server. If you have access to your router management page, you should easily be able to see the IP address for your machine here. In my case it’s 192.168.1.83.

Alternatively you can use a third party application like Fing.

Or you can find your IP by typing the following command into your terminal.

ifconfig -a

If there is too much information displayed on the screen and you are unable to see the first adapters, you can use the following command.

ifconfig -a | less

Depending on whether you are connected by Ethernet or Wifi, look for a device named something like ‘enp0sxx‘ or ‘wlanx‘ and you should see your local IP address. I am connected through Ethernet and my local IP address is 192.168.1.83.

Now we know the IP address, we can open Home Assistant in the web browser. By default home assistant runs on port 8123, therefore you need to navigate to your IP and specify this port.

http://<your-ip>:8123

If all has been successful you will be greeted with the Home Assistant login page. Go ahead and create a user name and password to log in to Home Assistant.

For those who are super-vigilant, you will notice that the IP address in the screenshot above is ‘localhost:8123

This is because I have been applying every step I have written here to a brand new installation of Ubuntu server and Hassio within a virtual machine on my Mac running Ubuntu Server. This is to ensure everything works properly and nothing is missed.

If I were to visit the Home Assistant page on my actual working server, it would be ‘http://192.168.1.83:8123/lovelace/default_view

If you are installing Hassio in Linux desktop using the local desktop and terminal, localhost may also work for you but to access it with another machine on your network, you will need the local IP address.

SSH access in Ubuntu

How you choose to setup your Home Assistant server is beyond the scope of this tutorial. However I wanted to highlight that you may run in to difficulty with SSH should you choose to use it to access Hassio.

It is likely that port 22 is already in use if you are using SSH to connect to your Linux machine. Therefore if you install the SSH server in Hassio, you will receive an error when you try to start the service.

It took me a while to figure this one out! In the end I had to ask the experts over at Github. The solution turned out to be quite simple, you must use a different port. Therefore in the setup for SSH, change your port to something like 23 and don’t forget to click save!

Then you can use the following command to access Hassio with SSH.

ssh user@<your-ip> -p 23

Tip: Port 23 can be reserved for Telnet and therefore may also be in use. In my case with a fresh install it was available, but you may want to choose a port in the private range between 49152 and 65535 to prevent any conflicts.

So you made it all the way to the end of the tutorial, take a sip of your beverage and give yourself a pat on the back! I hope that this guide helped you achieve your goal with setting up Home Assistant on Ubuntu. Please check out some of my other cool tutorials!

back to top