Install LXD on RHEL without snap

Install golang

Download latest version of go (RHEL 9 go version is older than needed by lxd-6.1) from https://go.dev/dl/:

cd /usr/local
wget 'https://go.dev/dl/go1.23.2.linux-amd64.tar.gz'
tar xf go1.23.2.linux-amd64.tar.gz

add go path to PATH:

export PATH="/usr/local/go/bin:${PATH}"

Install lxd

dnf install -y lxc lxc-devel libuv-devel sqlite-devel systemd-devel libcap-devel libacl-devel

Download latest release source code of LXD from https://github.com/canonical/lxd/releases

cd /usr/local/src
wget https://github.com/canonical/lxd/archive/refs/tags/lxd-6.1.tar.gz -O lxd-6.1.tar.gz
tar xf lxd-6.1.tar.gz
cd lxd-lxd-6.1/
make deps

pay attention to make deps output at the end. it looks something like:

# Please set the following in your environment (possibly ~/.bashrc)
export CGO_CFLAGS="-I/root/go/deps/dqlite/include/"
export CGO_LDFLAGS="-L/root/go/deps/dqlite/.libs/"
export LD_LIBRARY_PATH="/root/go/deps/dqlite/.libs/"
export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"

run those exports - they are needed for the build process

make -j $(nproc)

add this to ~/.bashrc:

# Add the LXD binaries to your PATH
export PATH="/usr/local/go/bin:${PATH}:/root/go/bin"
export LD_LIBRARY_PATH="$(go env GOPATH)/deps/dqlite/.libs/:${LD_LIBRARY_PATH}"

test lxd:

lxd version
echo "root:6553600000:1000000000" | sudo tee -a /etc/subuid /etc/subgid
useradd --system lxd
getent group lxd >/dev/null || sudo groupadd --system lxd # create the group if needed
getent group lxd | grep -qwF "$USER" || sudo usermod -aG lxd "$USER"

create a file /etc/systemd/system/lxd.service

[Unit]
Description=LXD Container Hypervisor
After=network-online.target
Wants=network-online.target

[Service]
Environment="PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin"
#Environment="LD_LIBRARY_PATH=/usr/local/lxd-4.0.10/vendor/raft/.libs/:/usr/local/lxd-4.0.10/vendor/dqlite/.libs/:${LD_LIBRARY_PATH}"
Environment="LD_LIBRARY_PATH=/root/go/deps/dqlite/.libs:${LD_LIBRARY_PATH}"
ExecStartPre=/bin/bash -c 'echo "PATH=$PATH" > /tmp/lxd_env.log'
ExecStartPre=/bin/bash -c 'echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> /tmp/lxd_env.log'
ExecStart=/usr/bin/sudo -E PATH=${PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} /root/go/bin/lxd --group wheel
LimitNOFILE=1048576
LimitNPROC=1048576

# Enable this if you want the LXD daemon to restart automatically on crashes
Restart=on-failure
RestartSec=5


[Install]
WantedBy=multi-user.target

enable and start the lxd service

systemctl start lxd.service
systemctl enable lxd.service