---
title: "How to Install and Use Snapcraft on Linux"
description: "Learn the ins-and-outs of package management with snapcraft on Linux and take control of your operating system!"
canonical: "https://adamtheautomator.com/snapcraft/"
---

# How to Install and Use Snapcraft on Linux

> Learn the ins-and-outs of package management with snapcraft on Linux and take control of your operating system!

Source: https://adamtheautomator.com/snapcraft/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Install and Use Snapcraft on Linux](https://adamtheautomator.com/wp-content/uploads/2022/09/How-to-Install-and-Use-Snapcraft-on-Linux.jpg)

# How to Install and Use Snapcraft on Linux

[![](https://secure.gravatar.com/avatar/1bc5e1d52466fc3739f550c8d78be310684747bf1466a98d698320627ea243e2?s=192&d=mm&r=g)Michael Nguyen Tu](https://adamtheautomator.com/author/michael-nguyen-tu/)3 October 20226 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing Snapd (Snap Daemon) and Snapcraft](#installing-snapd-snap-daemon-and-snapcraft)
*   [Initializing a Snap Project with Snapcraft](#initializing-a-snap-project-with-snapcraft)
*   [Configuring and Building a Snap](#configuring-and-building-a-snap)
*   [Testing Your Snap](#testing-your-snap)
*   [Conclusion](#conclusion)

If you are looking for a better way to manage software in your Linux system, you may want to check out Snapcraft. With Snapcraft, you can search for, install, and manage software with a few clicks while finding, sharing, and creating new snaps with the community.

In this tutorial, you will learn how to install Snapcraft, create a basic snap and install it on your Linux system.

Ready? Stay tuned and explore how Snapcraft can make your software management life easier!

## Prerequisites

This tutorial will be a hands-on demonstration, and you will need a Linux system to follow along. This tutorial uses Ubuntu 20.04, but any derivatives will work.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## Installing Snapd (Snap Daemon) and Snapcraft

Before creating or even running snaps, you first need to install Snapd, a daemon required to run snaps. Snapd also lets you install and enable Snapcraft on your system.

To install Snapd on Ubuntu:

1\. Run the followin`g [apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update)` command to update your Ubuntu repositories.

```bash
apt update -y
```

![Updating your Ubuntu repositories](https://adamtheautomator.com/wp-content/uploads/2022/09/Untitled-1.png)

Updating your Ubuntu repositories

2\. Next, run the below [`apt install`](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command to install Snapd.

```bash
apt install snapd -y
```

![Installing Snapd (Snap Daemon)](https://adamtheautomator.com/wp-content/uploads/2022/09/image-618.png)

Installing Snapd (Snap Daemon)

3\. Once installed, run the `snap` command below to check the version of Snapd installed on your system.

```bash
snap --version
```

![Checking the installed version of Snapd](https://adamtheautomator.com/wp-content/uploads/2022/09/image-619.png)

Checking the installed version of Snapd

4\. Lastly, run the `snap install` command below to install `snapcraft`.

Snapcraft is a powerful tool that lets you create snaps for various applications. You just need to declare the dependencies for your snap, and Snapcraft will do the rest.

```bash
snap install --classic snapcraft
```

Below, you can see the output confirms Snapcraft has been installed successfully.

![Installing Snapcraft](https://adamtheautomator.com/wp-content/uploads/2022/09/image-620.png)

Installing Snapcraft

## Initializing a Snap Project with Snapcraft

Now that you have Snapcraft installed, you are ready to create snaps. A snap is a self-contained application package that includes all the dependencies and libraries required to run an application. With a snap (pun intended), you can quickly install and manage applications on Linux.

Snaps are also secure and isolated from the rest of your system, which helps keep your system safe from malware. You can even upload your snaps to the Snap Store for others to use, or you can download snaps from the Snap Store to use on your system.

To see how Snapcraft works in action, you will create a simple snap for a “hello world” application. But first, you need a project directory to initialize a Snapcraft project:

1\. Run the following commands to create a directory (`mkdir`) for your snap and move into that directory (`cd`). This directory will hold all files related to your snap, where you will also run all the following commands.

> _You must omit spaces in your directory names when working with Snapcraft to avoid problems, such as build failures._

```bash
# Create a project directory
mkdir -p ~/mysnaps/hello
# Change the working directory
cd ~/mysnaps/hello
```

![Creating a project directory](https://adamtheautomator.com/wp-content/uploads/2022/09/image-621.png)

Creating a project directory

2\. Now, run the `snapcraft` command below to initialize (`init`) your Snapcraft project.

This command creates a _snapcraft.yaml_ and other environment files in the current directory. This file is used to declare dependencies and different settings for your snap.

```bash
snapcraft init
```

![Initializing a snap project](https://adamtheautomator.com/wp-content/uploads/2022/09/image-622.png)

Initializing a snap project

3\. Finally, run the below `tree` command to check your snap directory. `tree -a`

```bash
tree -a
```

At this point, you should have a directory structure that looks like the one below. This structure is known as a snap tree.

![Verifying the snap directory structure](https://adamtheautomator.com/wp-content/uploads/2022/09/image-623.png)

Verifying the snap directory structure

## Configuring and Building a Snap

After initializing your Snapcraft project, you are almost ready to create your snap with Snapcraft. But first, you need to declare some metadata for your snap. This metadata includes the name, version, summary, and description of your snap. And you can also specify the license for your snap and confinement level.

How? By editing the automatically generated _snapcraft.yaml_ file when you initialized your project.

1\. Open the _snapcraft.yaml_ file in your preferred text editor.

Related:[How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/powershell-text-editor/)

```bash
nano snap/snapcraft.yaml
```

2\. Next, replace the pre-generated contents of the file with the following lines to declare metadata for your snap.

But do not close the file yet since you will add parts of the configuration one at a time to understand better how the snap is configured.

```bash
# Your snap's name (must be in lowercase) and can contain letters, numbers, and hyphens.
name: hello
# The base snap that your snap will be built on top of. 
# core18 base is based on Ubuntu 18.04 (Bionic Beaver).
base: core18
# The current snap's version (incremental)
version: '2.10'
# One-line snap description
summary: GNU Hello, the "hello world" snap
# Long snap description. It can span multiple lines and can contain Markdown formatting.
description: |

 GNU hello prints a friendly greeting.

# Sets the snap's security grade (devel). 
# devel grade - used for development snaps that are not for general release. 
# stable grade - used for snaps considered ready for production use. 
# candidate grade - used for snaps ready for final testing (before stable grade).
grade: devel
# Sets the snap's confinement level (devmode)
# devmode - the least secure level where snap has full access to the host system.
# strict - the most secure level where snap has limited access to the host system.
# classic - somewhere in between where snap has limited access to the host system 
          # with some security features disabled.
confinement: devmode
```

3\. Add the following code below the `confinement` line to expose an app.

This code tells Snapcraft that your snap contains an app called `hello` that can be run with the `bin/hello` command.

```bash
apps:

 hello:

  command: bin/hello
```

4\. Now, add the following code at the end of the _snapcraft.yaml_ file which adds a part to your snap. A part describes the components of your snap, how they should be built, and where they can be found.

This code adds a part called `gnu-hello`, based on the official hello package from Ubuntu 18.04.

> _Note that your snap can contain multiple parts, but you will just need one in this tutorial._

```bash
parts:
  gnu-hello:
    source: http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
    plugin: autotools
```

At this point, you should have a _snapcraft.yaml_ file that looks like the one below. Save the changes and close the file.

```bash
# Your snap's name (must be in lowercase) and can contain letters, numbers, and hyphens.
name: hello
# The base snap that your snap will be built on top of. 
# core18 base, which is based on Ubuntu 18.04 (Bionic Beaver).
base: core18
# The current snap's version (incremental)
version: '2.10'
# One-line snap description
summary: GNU Hello, the "hello world" snap
# Long snap description. It can span multiple lines and can contain Markdown formatting.
description: |

 GNU hello prints a friendly greeting.

# Sets the snap's security grade (devel). 
# devel grade - used for development snaps that are not for general release. 
# stable grade - used for snaps considered ready for production use. 
# candidate grade - used for snaps ready for final testing (before stable grade).
grade: devel
# Sets the snap's confinement level (devmode)
# devmode - the least secure level where snap has full access to the host system.
# strict - the most secure level where snap has limited access to the host system.
# classic - somewhere in between where snap has limited access to the host system 
          # with some security features disabled.
confinement: devmode

# Expose an application called "hello" that can be run with the bin/hello command.
apps:

 hello:

  command: bin/hello

# Adding parts to describe the components of your snap, 
  # how they should be built and where they can be found.
parts:
  gnu-hello:
    source: http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
    plugin: autotools
```

5\. Finally, run the below `snapcraft` command after all the hard work to build your first snap.

```bash
snapcraft
```

The first time you run the `snapcraft` command, you will be prompted to install [Multipass](https://multipass.run/), as shown below. Multipass manages virtual machines for building snaps, and Snapcraft uses virtual machines to build snaps in a clean and isolated environment.

Related:[Take Control of VMs and Install VirtualBox on Ubuntu 20.04](https://adamtheautomator.com/virtualbox-on-ubuntu-2004/)

Type **y** and press **Enter** to continue.

![Building a snap with Snapcraft ](https://adamtheautomator.com/wp-content/uploads/2022/09/image-624.png)

Building a snap with Snapcraft

The building process downloads all dependencies and builds them from the source, which takes a while to complete. Once built, you will see an output similar to the one below.

As you can see, **hello\_2.10\_amd64.snap** is the package that was created, which is your snap package and can now be installed on any Linux distribution that supports snaps.

![Verifying the newly-created snap](https://adamtheautomator.com/wp-content/uploads/2022/09/image-625.png)

Verifying the newly-created snap

## Testing Your Snap

You have successfully built your snap, but how do you know it works? Put your newly-created snap to the test by installing it on your system and running your “hello world” application.

1\. Run the following `snap` command to `install` your newly-created snap package (`hello_2.10_amd64.snap`) on your system.

```bash
snap install --devmode hello_2.10_amd64.snap
```

![Installing the newly-created snap package](https://adamtheautomator.com/wp-content/uploads/2022/09/image-626.png)

Installing the newly-created snap package

2\. Next, execute the `hello` command below, which you declared in the _snapcraft.yaml_ file to run the `hello` app included in your snap.

```bash
hello
```

If everything worked as expected, you should see the “Hello, world!” message printed on the screen as shown.

![Running the hello app](https://adamtheautomator.com/wp-content/uploads/2022/09/image-627.png)

Running the hello app

3\. Finally, run the `snap list` command below to get the installed snap’s (`hello`) information.

```bash
snap list hello
```

![Getting the installed snap’s information](https://adamtheautomator.com/wp-content/uploads/2022/09/image-628.png)

Getting the installed snap’s information

## Conclusion

Software management can be tedious work unless you have a dependable tool at your disposal. And in this tutorial, you learned how to install and use Snapcraft to create a simple snap to manage and install software on your Linux system without hassle.

After seeing how Snapcraft works, why not start creating more [complex snaps](https://snapcraft.io/blog/lets-build-a-snap-together-a-complex-snapcraft-yaml-walkthrough) and [upload](https://snapcraft.io/docs/releasing-your-app) them to the Snap Store for others to install and use?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fsnapcraft%2F&text=How%20to%20Install%20and%20Use%20Snapcraft%20on%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fsnapcraft%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fsnapcraft%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
