---
title: Building the MicroK8s snap
description: Canonical makes open source secure, reliable and easy to use, providing
  support for Ubuntu and a portfolio of enterprise-grade technologies. Founded in
  2004, Canonical operates globally with team members in over 80 countries.
url: https://canonical.com/microk8s/docs/build-microk8s-snap?format=md
---

*Submit*

# Building the MicroK8s snap

MicroK8s is usually distributed as a snap package, to make it easy to distribute and install securely across a range of operating systems. As MicroK8s is completely open source, it is possible to modify or customise the source and build your own snap.

### [What you will need](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-what-you-will-need)

* Access to the internet (see section on oflline builds below)
* A working [LXD](https://documentation.ubuntu.com/lxd/) environment
* The latest version of [Snapcraft](https://snapcraft.io/docs/)

### [Install LXD if required](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-install-lxd-if-required)

The Snapcraft build process makes use of an LXD container. This needs to be of a recent, snap-based distribution of LXD.
Remove any previous versions of LXD/LXC (be sure to snapshot any running containers first!):

```
sudo apt-get remove lxd* -y
sudo apt-get remove lxc* -y
```

Then install the LXD snap package

```
snap install lxd
```

… and initiate the LXD environment.

```
lxd init
```

For more detailed install instructions, refer to the [LXD documentation](https://documentation.ubuntu.com/lxd/).

### [Install Snapcraft](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-install-snapcraft)

Snapcraft is the tool which builds snap packages. For full installation instrctions, see the [Snapcraft overview](https://snapcraft.io/docs/snapcraft-overview), but for platforms which support snaps, it can be installed simply by running:

```
sudo snap install snapcraft --classic
```

### [Fetch the MicroK8s source](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-fetch-the-microk8s-source)

MicroK8s source code is located on [Github](https://github.com/canonical/microk8s). To fetch a local copy:

```
git clone http://github.com/canonical/microk8s
cd ./microk8s/
```

### [Make modifications](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-make-modifications)

At this stage you can modify any of the code in the repo. Many modifications may be limited to the ‘recipe’ used to build the snap - the `snapcraft.yaml` file, which can be found in the `snap`directory. You should again refer to the Snapcraft documentation for the settings found in this file. It is also useful to know there are a number of variables which can be set to influence the build process, which can be set either in the snapcraft.yaml file of the container itself - a list of these can be found in the [build reference documentation](https://canonical.com/microk8s/docs/ref-build-env).

### [Build the snap](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-build-the-snap)

As mentioned there are many settings and options for using snapcraft. the recommended method for building the MicroK8s snap is to use an LXD container. You can initiate the build with the command:

```
snapcraft --use-lxd
```

This will take some time as the build process fetches dependencies, stages the ‘parts’ of the snap and creates the snap package itself. the snap itself will be fetched from the build environment and placed in the local project directory. Note that the LXD container used for building will be stopped, but not deleted. This is in case there were any errors or artefacts you may wish to inspect.

### [Install the snap](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-install-the-snap)

The snap can then be installed locally by using the ‘–dangerous’ option. This is a safeguard to make sure the user is aware that the snap is not signed by the snap store, and is not confined.

```
sudo snap install microk8s_v1.27.3_amd64.snap
```

Note: You will not be able to install this snap if there is already a `microk8s`snap installed on your system.

### [Iterate over changes](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-iterate-over-changes)

When you are done testing the changes you have made, you can remove the snap:

```
sudo snap remove microk8s
```

If you wish you can then make further changes. As noted previously, the LXD container used for building is not removed and will be reused by subsequent build instructions. When you are satisfied it is no longer needed, this container can be removed:

```
lxc delete snapcraft-microk8s
```

## [Building offline for air-gapped environments](https://canonical.com/microk8s/docs/build-microk8s-snap?format=md#p-40632-building-offline-for-air-gapped-environments)

A common use case is where MicroK8s is used in an airgapped or offline environment. To be able to build the MicroK8s snap in that environment requires that the source for the snap and all dependencies are available, many of which are normally fetched from online resources.

In this scenario, it is usually simplest to run through the above steps on a computer which does have access to these resources, and then transfer them to the environment where the build is to be made (following whatever normal procedures are required in the environment to declare these resources ‘safe’).

This directory can then be examined and copied to the offline environment. Please note that disconnecting from the source in this way obviously means you will not receive any, possibly important, updates. See also the documentation for [installing in an offline environment](https://canonical.com/microk8s/docs/install-offline)

Last updated 3 years ago. [Help improve this document in the forum](https://discuss.kubernetes.io/t/building-the-microk8s-snap/24710).
