Guide: Installing Home Assistant Core on Ubuntu 22.04

I was logged in as user “root”. If you use another user, first type “sudo -s” or “su” to get root access.

Install Home Assistant Core on Ubuntu 22.04

  1. apt update && apt upgrade
    optionally to make sure all packages are installed correctly:

    • dpkg --configure -a
    • apt install -f
    • apt-get --fix-broken install
    • apt-get update --fix-missing
    • apt update && apt upgrade
  2. add-apt-repository ppa:deadsnakes/ppa

  3. apt update

  4. apt install wget build-essential libncursesw5-dev libssl-dev
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

  5. apt install python3.11 python3.11-dev python3.11-venv python3-pip

  6. Change the first line in files “/usr/bin/pip” & “/usr/bin/pip3” to “#!/usr/bin/python3.11”

  7. apt install bluez libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata ffmpeg liblapack3 liblapack-dev libatlas-base-dev

  8. useradd -rm homeassistant -G dialout

  9. mkdir /srv/homeassistant

  10. chown homeassistant:homeassistant /srv/homeassistant

  11. sudo -u homeassistant -H -s

  12. cd /srv/homeassistant

  13. python3.11 -m venv .

  14. source bin/activate

  15. python3.11 -m pip install wheel

  16. pip3 install homeassistant==2023.8.3

  17. hass

  18. Create file (init.d script) “/etc/init.d/homeassistant”

#!/bin/sh
# For Ubuntu:
# description: Home Assistant
# processname: hass

### BEGIN INIT INFO
# Provides:          hass
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Home Assistant service
# Description:       Home Assistant
### END INIT INFO

name="HomeAssistant"
pid_file="/var/run/$name.pid"

case "$1" in
    start)
		su - homeassistant -c '/srv/homeassistant/bin/python3.11 /srv/homeassistant/bin/hass' &>/dev/null &
		echo $(pgrep python3.11) > "$pid_file"
		echo "Running with PID: $(pgrep python3.11)"
    ;;
    stop)
        echo -n "Stopping $name.."
        kill $(pgrep python3.11)
	rm "/var/run/$name.pid"

    ;;
    restart)
        stop
		start
    ;;
    status)
        if $(pgrep hass); then
            echo "Running with PID: $(pgrep python3.11)"
        else
            echo "$name is not running"
            exit 1
        fi

    ;;
    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac
exit 0
  1. chmod 0755 /etc/init.d/homeassistant

  2. update-rc.d homeassistant defaults

  3. reboot

  4. Check if Home Assistant is running:
    service homeassistant status

  5. Done

  6. Go to “http:// « ip address » :8123”

  7. Close the session to end root access

Worked for me :slightly_smiling_face:

3 Likes

Hi,
Nice guide, I am sure that it will help someone, but I can’t understand why you not using systemd to start/stop service. This init.d script looks wrong, particulary stop section:

    stop)
        echo -n "Stopping $name.."
        kill $(pgrep python3.11)

will basically kill all running python 3.11 processes.
I am running Home Assistant Core for a long time under Ubuntu 18.04 and now 22.04, plus zigbee2mqtt, zwave-js-ui (zwavejs2mqtt), AppDaemon, Node Red.
Here is my systemd unit just for example:

igor@hass:~$ cat /etc/systemd/system/[email protected]
[Unit] 
Description=Home Assistant
After=network-online.target
After=zigbee2mqtt.service
[Service]
Type=simple
User=%i
ExecStart=/srv/hass311/bin/hass -c "/home/%i/.homeassistant"
Restart=always
StandardOutput=journal
StandardError=journal+console
[Install]
WantedBy=multi-user.target
1 Like

Thank you for this guide, it worked for me! :+1:

Before step 18 Create file (init.d script) “/etc/init.d/homeassistant” I had to switch back to the root user so I could write to “/etc/init.d/homeassistant” but other than that it went flawlessly and I have been through several other guides before that seemed to leave out a lot of details and never worked, so I am glad I found this.

I ran into many errors in Ubuntu 22.04 (Virtualization Station on QNAP):

2023-12-10 09:10:17.239 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package aiohue==4.7.0: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fefe50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fe2d50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fe4950>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fe4f50>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fe5850>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Max retries exceeded with url: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata (Caused by NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fc385fe6050>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’))
2023-12-10 09:10:26.945 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package aiohue==4.7.0: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf082a3d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf0832fd0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf0833850>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf0831b90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf0838690>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)‘: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Max retries exceeded with url: /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata (Caused by NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbbf0839090>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’))
2023-12-10 09:10:37.383 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package aiohue==4.7.0: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3fd90eb4d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /packages/f0/91/fdde4b2bbfea57856674ebd6168c235d2b69027fc30486f3f7c243b6723a/aiohue-4.7.0-py3-none-any.whl.metadata

issue:
my server doesn’t have bluetooth. and i run into an issue w/ this at ‘hass’

[homeassistant.setup] Setup of bluetooth is taking over 10 seconds.

hangs forever
& 2nd try no output - just hangs

any way i can mod to exclude bluetooth setup? i’m looking thru files now but no obvious solution yet

much obliged to anyone who can help, as unless i post again that i figured it out, means i’m still stuck - God bless

-p

I have the same issue. Cannot install, it hangs because of the bluetooth which is missing. How to install HA?

I installed Linux to one of my laptop. Bluetooth is present there and is workng fine. But the HA install hangs there also, claiming thet it could not reset the power state of the bluetooth adapter, and could not cycle it. And this error is in loop forever…

2024-01-09 12:31:42.986 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not reset the power state of the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] due to timeout after 5 seconds
2024-01-09 12:31:42.988 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not cycle the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED]: [Errno 1] Operation not permitted
2024-01-09 12:31:42.988 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth management socket connection lost: [Errno 22] Invalid argument
2024-01-09 12:31:47.989 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] could not be reset: 
2024-01-09 12:31:47.992 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] failed: [Errno 9] Bad file descriptor
2024-01-09 12:33:13.307 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not reset the power state of the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] due to timeout after 5 seconds
2024-01-09 12:33:13.309 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not cycle the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED]: [Errno 1] Operation not permitted
2024-01-09 12:33:13.310 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth management socket connection lost: [Errno 22] Invalid argument
2024-01-09 12:33:18.311 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] could not be reset: 
2024-01-09 12:33:18.313 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] failed: [Errno 9] Bad file descriptor
2024-01-09 12:34:43.584 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not reset the power state of the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] due to timeout after 5 seconds
2024-01-09 12:34:43.586 WARNING (MainThread) [bluetooth_auto_recovery.recover] Could not cycle the Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED]: [Errno 1] Operation not permitted
2024-01-09 12:34:43.587 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth management socket connection lost: [Errno 22] Invalid argument
2024-01-09 12:34:48.589 WARNING (MainThread) [bluetooth_auto_recovery.recover] Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] could not be reset: 
2024-01-09 12:34:48.591 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [C0:CB:38:AE:7A:ED] failed: [Errno 9] Bad file descriptor
1 Like

The install worked for me, however, the add-ons is missing. How to go about enabling and using add-ons or is it not possible?

ubu@ubu-desktop
OS: Ubuntu 23.10 mantic
Kernel: aarch64 Linux 6.5.0-1013-raspi
Uptime: 22m
Packages: 2612
Shell: bash 5.2.15
Disk: 24G / 110G (23%)
CPU: BCM2835 @ 4x 1.5GHz

RAM: 1372MiB / 3789MiB

Worked for me , thanks a lot.

Thank you for this guide, it was OK for me.
Just 3 points:

  • My bluetooth device was not correctly managed too, so hass command in step 17 output a lot of warning message (see mcll post)… BUT, after interrupting hass execution I could see that installation was correctly completed, so I could login in homeassistant GUI and disable Bluetooth item in order to avoid bluetooth_auto_recovery.recover messages
  • To install 2024.3.3 version, I’ve changed every occurence of python3.11 to python3.12 (step 5, 6, 13 and 15)
  • To manage service start/stop in Ubuntu 22.04 I’ve used systemctl environment, setup as following:
    As root create file /etc/systemd/system/[email protected] with the content:
[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"
Restart=always
StandardOutput=journal
StandardError=journal+console

[Install]
WantedBy=multi-user.target

then run:
systemctl enable [email protected]
systemctl start [email protected]

My “home” 2 cents