How to install LXD¶
There are multiple approaches to installing LXD, depending on your Linux distribution, operating system, and use case.
Install the LXD snap package¶
The recommended way to install LXD is its snap package, available for many Linux distributions. For alternative methods, see: Other Linux installation options, Other operating systems, or Install LXD from source.
Requirements¶
The LXD snap must be available for your Linux distribution.
The
snapd
daemon must be installed.
Install¶
Use this command to install LXD from the recommended default snap track (currently 5.21):
sudo snap install lxd
If you are installing LXD on a cluster member, add the --cohort="+"
flag to keep cluster members synchronized to the same snap version:
sudo snap install lxd --cohort="+"
Next, follow the Post-installation steps below.
Optionally specify a channel¶
Channels correspond to different LXD releases. When unspecified, the LXD snap defaults to the most recent stable
LTS, which is recommended for most use cases.
To specify a different channel, add the --channel
flag at installation:
sudo snap install lxd --channel=<target channel> [--cohort="+"]
For example, to use the 6/stable
channel, run:
sudo snap install lxd --channel=6/stable
For details about LXD snap channels, see: Channels.
Post-installation¶
Follow these steps after installing the LXD snap.
Add the current user¶
To allow the current user to interact with the LXD daemon, update the lxd
group:
getent group lxd | grep -qwF "$USER" || sudo usermod -aG lxd "$USER"
Afterward, apply the change to your current shell session by running:
newgrp lxd
For more information, see the Manage access to LXD section below.
Hold or schedule updates¶
When a new release is published to a snap channel, installed snaps following that channel update automatically by default.
For LXD clusters, or on any machine where you want control over updates, you should override this default behavior by either holding or scheduling updates. See: Manage updates.
Other Linux installation options¶
Some Linux installations can use package managers other than Snap to install LXD. These managers all install the latest feature release.
Run:
apk add lxd
Run:
pacman -S lxd
Fedora RPM packages for LXC/LXD are available in the COPR repository. These are unofficial and minimally tested; use at your own risk.
View the installation guide for details.
Run:
emerge --ask lxd
Following installation, make sure to manage access to LXD.
Other operating systems¶
Builds of the lxc
client are available for non-Linux operating systems to enable interaction with remote LXD servers. For more information, see: About lxd
and lxc
.
The Homebrew package manager must be installed on your system.
To install the client from the latest feature release of LXD, run:
brew install lxc
The Chocolatey package manager must be installed on your system.
To install the client from the latest feature release of LXD, run:
choco install lxc
Native builds of the client¶
You can find native builds of the lxc
client on GitHub:
To download a specific build:
Make sure that you are logged into your GitHub account.
Filter for the branch or tag that you are interested in (for example, the latest release tag or
main
).Select the latest build and download the suitable artifact.
These builds are for the lxc
client only, not the LXD daemon. For an explanation of the differences, see: About lxd
and lxc
.
Install LXD from source¶
These instructions for building and installing from source are suitable for developers who want to build the latest version of LXD, or to build a specific release of LXD which may not be offered by their Linux distribution. Source builds for integration into Linux distributions are not covered.
We recommend having the latest versions of liblxc
(see LXC requirements)
available for LXD development. For convenience, make deps
will pull the
appropriate versions of liblxc
and dqlite
from their corresponding upstream
Git repository. Additionally, LXD requires a modern Golang (see
Go) version to work. On Ubuntu, you can install these with:
sudo apt update
sudo apt install \
autoconf \
automake \
build-essential \
gettext \
git \
libacl1-dev \
libapparmor-dev \
libcap-dev \
liblz4-dev \
libseccomp-dev \
libsqlite3-dev \
libtool \
libudev-dev \
libuv1-dev \
make \
meson \
ninja-build \
pkg-config \
python3-venv
command -v snap >/dev/null || sudo apt-get install snapd
sudo snap install --classic go
Note
If you use the liblxc-dev
package and get compile time errors when building the go-lxc
module,
ensure that the value for LXC_DEVEL
is 0
for your liblxc
build. To check this, look at /usr/include/lxc/version.h
.
If the LXC_DEVEL
value is 1
, replace it with 0
to work around the problem. It’s a packaging bug that is now fixed,
see LP: #2039873.
There are a few storage drivers for LXD besides the default dir
driver. Installing these tools adds a bit to initramfs
and may slow down your host boot, but are needed if you’d like to use a particular driver:
sudo apt install lvm2 thin-provisioning-tools
sudo apt install btrfs-progs
At runtime, LXD might need the following packages to be installed on the host system:
sudo apt update
sudo apt install \
attr \
iproute2 \
nftables \
rsync \
squashfs-tools \
tar \
xz-utils
# `nftables` can be replaced by `iptables` on older systems
To run the test suite or test related make
targets, you’ll also need:
sudo apt update
sudo apt install \
acl \
bind9-dnsutils \
btrfs-progs \
busybox-static \
curl \
dnsmasq-base \
dosfstools \
e2fsprogs \
iputils-ping \
jq \
netcat-openbsd \
openvswitch-switch \
s3cmd \
shellcheck \
socat \
sqlite3 \
swtpm \
xfsprogs \
yq
From source: Build the latest version¶
These instructions for building from source are suitable for individual developers who want to build the latest version of LXD, or build a specific release of LXD which may not be offered by their Linux distribution. Source builds for integration into Linux distributions are not covered here and may be covered in detail in a separate document in the future.
git clone https://github.com/canonical/lxd
cd lxd
This will download the current development tree of LXD and place you in the source tree. Then proceed to the instructions below to actually build and install LXD.
From source: Build a release¶
The LXD release tarballs bundle a complete dependency tree as well as a
local copy libdqlite
for LXD’s database setup.
tar zxvf lxd-4.18.tar.gz
cd lxd-4.18
This will unpack the release tarball and place you inside of the source tree. Then proceed to the instructions below to actually build and install LXD.
Start the build¶
The actual building is done by two separate invocations of the Makefile: make deps
– which builds libraries required
by LXD – and make
, which builds LXD itself. At the end of make deps
, a message will be displayed which will specify environment variables that should be set prior to invoking make
. As new versions of LXD are released, these environment
variable settings may change, so be sure to use the ones displayed at the end of the make deps
process, as the ones
below (shown for example purposes) may not exactly match what your version of LXD requires:
We recommend having at least 2GiB of RAM to allow the build to complete.
~$
make deps
...
make[1]: Leaving directory '/root/go/deps/dqlite'
# environment
Please set the following in your environment (possibly ~/.bashrc)
# export CGO_CFLAGS="${CGO_CFLAGS} -I$(go env GOPATH)/deps/dqlite/include/"
# export CGO_LDFLAGS="${CGO_LDFLAGS} -L$(go env GOPATH)/deps/dqlite/.libs/"
# export LD_LIBRARY_PATH="$(go env GOPATH)/deps/dqlite/.libs/${LD_LIBRARY_PATH}"
# export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
~$
make
From source: Install¶
Once the build completes, you simply keep the source tree, add the directory referenced by $(go env GOPATH)/bin
to
your shell path, and set the LD_LIBRARY_PATH
variable printed by make deps
to your environment. This might look
something like this for a ~/.bashrc
file:
export PATH="${PATH}:$(go env GOPATH)/bin"
export LD_LIBRARY_PATH="$(go env GOPATH)/deps/dqlite/.libs/:${LD_LIBRARY_PATH}"
Now, the lxd
and lxc
binaries will be available to you and can be used to set up LXD. The binaries will automatically find and use the dependencies built in $(go env GOPATH)/deps
thanks to the LD_LIBRARY_PATH
environment variable.
Machine setup¶
You’ll need sub{u,g}ids for root, so that LXD can create the unprivileged containers:
echo "root:1000000:1000000000" | sudo tee -a /etc/subuid /etc/subgid
By default, only users added to the lxd
group can interact with the LXD daemon. Installing from source doesn’t guarantee that the lxd
group exists in the system. If you want the current user (or any other user) to be able to interact with the LXD daemon, create the group and add the user to it:
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"
Afterward, apply the change to your current shell session by running:
newgrp lxd
Now you can run the daemon (the --group sudo
bit allows everyone in the sudo
group to talk to LXD; you can create your own group if you want):
sudo -E PATH=${PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH} $(go env GOPATH)/bin/lxd --group sudo
Note
If newuidmap/newgidmap
tools are present on your system and /etc/subuid
, etc/subgid
exist, they must be configured to allow the root user a contiguous range of at least 10M UID/GID.
Shell completions¶
Shell completion profiles can be generated with lxc completion <shell>
(e.g. lxc completion bash
). Supported shells are bash
, zsh
, fish
, and powershell
.
lxc completion bash > /etc/bash_completion.d/lxc # generating completions for bash as an example
. /etc/bash_completion.d/lxc
Manage access to LXD¶
Access control for LXD is based on group membership. The root user and all members of the lxd
group can interact with the local daemon.
On Ubuntu images, the lxd
group already exists and the root user is automatically added to it. The group is also created during installation if you installed LXD from the snap.
To check if the lxd
group exists, run:
getent group lxd
If this command returns no result, the lxd
group is missing from your system. This might be the case if you installed LXD from source. To create the group and restart the LXD daemon, run:
getent group lxd >/dev/null || sudo groupadd --system lxd
Afterward, add trusted users to the group so they can use LXD. The following command adds the current user:
getent group lxd | grep -qwF "$USER" || sudo usermod -aG lxd "$USER"
Afterward, apply the change to your current shell session by running:
newgrp lxd
Important security notice
Local access to LXD through the Unix socket always grants full access to LXD. This includes the ability to attach file system paths or devices to any instance as well as tweak the security features on any instance.
Therefore, you should only give such access to users who you’d trust with root access to your system.
For more information, see Access to the LXD daemon.
Upgrade LXD¶
After upgrading LXD to a newer version, LXD might need to update its database to a new schema.
This update happens automatically when the daemon starts up after a LXD upgrade.
A backup of the database before the update is stored in the same location as the active database (for example, at /var/snap/lxd/common/lxd/database
for the snap installation).
Important
After a schema update, older versions of LXD might regard the database as invalid. That means that downgrading LXD might render your LXD installation unusable.
In that case, if you need to downgrade, restore the database backup before starting the downgrade.