How To Install LXD on Ubuntu 24.04

LXD Logo

What is LXD ?

LXD is a powerful system container and virtual machine manager that provides a user-friendly way to manage Linux containers. It is an extension of LXC (Linux Containers), offering a higher-level interface with additional features such as image management, networking, and storage handling. In this guide, we will cover how to install and configure LXD on Ubuntu 24.04 Linux operating system.

Key Features of LXD:

  1. System Containers & VMs: LXD supports both system containers (lightweight, OS-level virtualization) and full virtual machines.
  2. User-friendly CLI & API: It provides an intuitive command-line interface (lxc) and a REST API for automation.
  3. Secure by Design: LXD uses unprivileged containers and security features like AppArmor and Seccomp.
  4. Scalability: LXD can run hundreds of containers efficiently on a single machine.
  5. Image Management: Built-in support for downloading and managing container images from remote repositories.
  6. Storage Flexibility: Supports ZFS, Btrfs, LVM, and directory-based storage.
  7. Networking Capabilities: Provides built-in bridged networks, IPv4/IPv6 support, and integration with OVN (Open Virtual Network).

How LXD Differs from Docker

FeatureLXD (System Containers)Docker (Application Containers)
VirtualizationOS-level (system containers)Process-level (application containers)
Use CaseRunning full Linux OS instancesRunning isolated apps and microservices
StorageSupports ZFS, Btrfs, LVM, etc.Uses UnionFS, OverlayFS, etc.
NetworkingAdvanced networking with bridgesSimple networking for app isolation

Who Should Use LXD?

  • Developers testing software in isolated environments.
  • Sysadmins managing multiple Linux instances efficiently.
  • Enterprises needing lightweight virtualization for production workloads.

Installing LXD on Ubuntu 24.04

Here’s a step-by-step guide to installing LXD on Ubuntu Linux:

  1. Update Your System
  2. Install LXD on Ubuntu
  3. Add User to LXD Group
  4. Initialize LXD
  5. Verify LXD Installation
  6. Create and Manage Containers with LXD
  7. Enable LXD to Start on Boot (Optional)
  8. Uninstall LXD (If Needed)

The details of LXD installation on Ubuntu 24.04 LTS operating system will be explained briefly in the sub chapter below.

Step 1: Update Your System

Before installing LXD, it is good practice to update your system packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install LXD on Ubuntu

There are two main ways to install LXD on Ubuntu: using APT (Default) and the using Snap.

Option 1: Install LXD Using APT (Default)

Ubuntu includes LXD in its official repositories, making installation straightforward:

sudo apt install -y lxd
Option 2: Install LXD Using Snap (Recommended for Latest Version)

For the latest version of LXD, it is recommended to install it via Snap. the installation will be as shown below. On this tutorial, we will be using this option.

sudo snap install lxd

Then check if LXD is installed correctly, by submitting command line :

lxd --version
sudo snap install lxd

Step 3: Add User to LXD Group

By default, only root users can run LXD commands. To allow your user to use LXD, add it to the lxd group:

sudo usermod -aG lxd $USER
newgrp lxd
id
lxc list
sudo usermod -aG lxd $USER

This change allows you to run LXD commands without sudo.

Step 4: Initialize LXD

LXD requires initialization before use. Run the following command:

lxd init

You will be prompted with a series of configuration questions, including storage backend and network setup. If you want a quick default setup, run:

lxd init –auto

Step 5: Verify LXD Installation

Check if LXD is installed correctly:

lxd --version

Ensure the LXD service is running:

Step 6: Create and Manage Containers with LXD

Once LXD is installed, you can start creating and managing containers.

6.1 Launch a New Container

On this tutorial, we will create a new bckinfo-container container named my-container, run:

lxc launch ubuntu:22.04 bckinf-container

6.2 List Running Containers

Check running containers with:

lxc list

6.3 Access the Container

To open a shell inside the container, run:

lxc exec bckinf-container -- bash

On this tutorial, we tried to access the container and submit a simple shell command to display the system name.

6.4 Stop and Delete a Container

To stop a container:

lxc stop bckinf-container

To delete a container:

lxc delete bckinf-container
lxc delete bckinf-container

Step 7: Enable LXD to Start on Boot (Optional)

To ensure LXD starts automatically on system boot, use:

sudo systemctl enable lxd

Step 8: Uninstall LXD (If Needed)

If you need to remove LXD, use:

sudo apt remove –purge lxd -y

Or, if installed via Snap:

sudo snap remove lxd
sudo snap remove lxd

Until this stage, we have learned how to install and configure LXD on Ubuntu 24.04 LTS operating system.

Conclusion

LXD is a powerful and efficient container manager for running lightweight Linux environments. Whether you’re a developer testing applications or an administrator managing workloads, LXD provides an easy-to-use, scalable solution. By following this guide, you can quickly install, configure, and start using LXD on Ubuntu. Happy containerizing!

(Visited 82 times, 1 visits today)

You may also like