How to Install Snapcraft on Ubuntu or CentOS

Reading Time: 6 minutes

What is Snapcraft?

Snapcraft is a command-line utility for building snaps. This software allows users to build their own applications or software packages, and then publish them to the Snap store to be shared and utilized by other users! In this tutorial, we will learn how to install Snapcraft on Ubuntu and CentOS.

What is Snap?

Snap, also known as Snappy, is a popular package management system for Linux that provides access to self-contained packages called snaps. The thing that sets Snap apart from other package management systems like yum or apt-get is that it isn't specific to just one Linux distribution. Yum, for example, is the default package manager for Fedora, CentOS, and Redhat, but distributions like Ubuntu and Debian use apt-get as the default package manager. Snap packages work on both Debian and RHEL based distributions because Snap encapsulates its own dependencies.

Pre-flight Check

  • CentOS requires access to the EPEL package repository to install snapd, which is a prerequisite to installing Snapcraft. Here is a tutorial on how to set up the epel repository.
  • These instructions are being performed on CentOS 7 and Ubuntu 18.04 LTS servers, respectively.
  • Ensure you are logged into these servers as the root user.

CentOS 7

Step 1: Install snapd

First, as a best-practice, ensure all packages are up to date:

yum update -y

Next install snapd:

yum install -y snapd

Step 2: Enable Snap.socket

After snapd is installed, you need to enable the snap.socket:

[root@host ~]# systemctl enable --now snapd.socket
Created symlink from /etc/systemd/system/sockets.target.wants/snapd.socket to /usr/lib/systemd/system/snapd.socket.
[root@host ~]# 

Step 3: Enable classic Snap support

Certain Snap packages require there to be a /snap directory. This capability doesn't ship with Snap itself, but to ensure you can install any Snap package, you will want to create a symlink to enable classic Snap support:

ln -s /var/lib/snapd/snap /snap

Next, refresh your terminal session:

exec bash

Step 4: Install Snapcraft

Now that snapd is installed, you are ready to install Snapcraft! The simplest way to get Snapcraft installed is to install it with Snap:

[root@host ~]# snap install snapcraft --classic
2019-10-10T10:54:15-04:00 INFO Waiting for restart...
snapcraft 3.8 from Canonical✓ installed
[root@host ~]# 

Install Error

Note:
During testing, we did encounter one error when trying to install snapcraft using snap on a CentOS 7 server. The error stated: “error: too early for operation, device not yet seeded or device model not acknowledged”. We uninstalled snapd [yum remove snapd] and then reinstalled it using [yum install -y snapd].
[root@host ~]# yum install -y snapd
Loaded plugins: fastestmirror, priorities, tmprepo
Loading mirror speeds from cached hostfile
 * base: mirrors.liquidweb.com
 * epel: mirrors.liquidweb.com
 * extras: mirrors.liquidweb.com
 * updates: mirrors.liquidweb.com
Resolving Dependencies
--> Running transaction check
---> Package snapd.x86_64 0:2.39.2-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package Arch Version Repository Size 

Installing:
 snapd  x86_64 2.39.2-1.el7 epel 14 M

Transaction Summary

Install  1 Package

Total download size: 14 M
Installed size: 43 M
Downloading packages:
snapd-2.39.2-1.el7.x86_64.rpm |  14 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : snapd-2.39.2-1.el7.x86_64  1/1 
  Verifying  : snapd-2.39.2-1.el7.x86_64  1/1 

Installed:
  snapd.x86_64 0:2.39.2-1.el7

Complete!

We then tried installing Snapcraft again:

[root@host ~]# snap install snapcraft --classic
error: too early for operation, device not yet seeded or device model not acknowledged

We waited for about ten minutes and then reran the Snapcraft install:

[root@host ~]# snap install snapcraft --classic
2019-10-10T11:11:15-04:00 INFO Waiting for restart...
snapcraft 3.8 from Canonical✓ installed
[root@host ~]# 
[root@host ~]# which snapcraft
/var/lib/snapd/snap/bin/snapcraft

Fixed!

Next, verify that Snapcraft is up and available:

[root@host ~]# snapcraft -h
<pre>Usage: snapcraft [OPTIONS] COMMAND [ARGS]...

  Snapcraft is a delightful packaging tool.

Options:
  --version    Show the version and exit.
  -d, --debug
  -h, --help   Show this message and exit.

Commands:
  build              Build artifacts defined for a part.
  clean              Remove a part's assets.
  close              Close <channel> for <snap-name>.
  create-key         Create a key to sign assertions.
  enable-ci          Enable continuous-integration systems to build and...
  expand-extensions  Display snapcraft.yaml with all extensions applied.
  export-login       Save login configuration for a store account in FILE.
  extension          Show contents of extension.
  gated              Get the list of snaps and revisions gating a snap.
  help               Obtain help for a certain topic, plugin or command.
  init               Initialize a snapcraft project.
  list-extensions    List available extensions.
  list-keys          List the keys available to sign assertions.
  list-plugins       List the available plugins that handle different types...
  list-registered    List snap names registered or shared with you.
  list-revisions     Get the history on the store for <snap-name>.
  login              Login with your Ubuntu One e-mail address and password.
  logout             Clear session credentials.
  pack               Create a snap from a directory holding a valid snap.
  prime              Final copy and preparation for the snap.
  pull               Download or retrieve artifacts defined for a part.
  push               Push <snap-file> to the store.
  push-metadata      Push metadata from <snap-file> to the store.
  register           Register <snap-name> with the store.
  register-key       Register a key with the store to sign assertions.
  release            Release <snap-name> on <revision> to the selected
                     store...
  sign-build         Sign a built snap file and assert it using the...
  snap               Create a snap.
  stage              Stage the part's built artifacts into the common...
  status             Get the status on the store for <snap-name>.
  try                Try a snap on the host, priming if necessary.
  validate           Validate a gated snap.
  version            Obtain snapcraft's version number.
  whoami             Returns your login information relevant to the store.
</pre>

If you see the above help output for the Snapcraft tool, you should be all set!

[root@host ~]# snapcraft --version
snapcraft, version 3.8
[root@host ~]# 

Ubuntu 18.04 LTS

Step 1: Verify snapd is available

As a best practice, update your packages:

apt-get update -y

Ubuntu distributions 16.04 and higher ship with snapd installed. Verify your Ubuntu distribution has snapd available. Your specific version information may differ, but the output should look similar to this:

root@host:~# snap --version
snap    2.38+18.04
snapd   2.38+18.04
series  16
ubuntu  18.04
kernel  4.15.0-50-generic
root@newmaster:~# 

If it does, you're all set! Move on to step two below.

If you see output similar to this:

Command' snap' not found, but can be installed with:
apt install snapd

You'll need to install snapd using apt:

Note:
When running “snap install snapcraft” if you get the error: “error: This revision of snap “snapcraft” was published using classic confinement and thus may perform arbitrary system changes outside of the security sandbox that snaps are usually confined to, which may put your system at risk. If you understand and want to proceed repeat the command including –classic.” simply run the “apt install snapcraft” command instead of the “snap install snapcraft” command. Snapcraft’s own instructions regarding the installation of snapcraft uses classic confinement.
apt-get install snapd -y

Step 2: Install Snapcraft

Now that you've verified snapd is available, you can install Snapcraft:

root@host:~# snap install snapcraft --classic
2019-10-10T11:31:12-04:00 INFO Waiting for restart...
snapcraft 3.8 from Canonical✓ installed
root@host:~#

To verify that Snapcraft is installed, check the help output. The following command will output all of the available options for Snapcraft.

root@host:~$ snapcraft --help
Usage: snapcraft [OPTIONS] COMMAND [ARGS]...

  Snapcraft is a delightful packaging tool.

Options:
  --version    Show the version and exit.
  -d, --debug
  --help       Show this message and exit.

Commands:
  build             Build artifacts defined for a part.
  clean             Remove content - cleans downloads, builds or install...
  cleanbuild        Create a snap using a clean environment managed by a...
  close             Close <channel> for <snap-name>.
  create-key        Create a key to sign assertions.
  define            Shows the definition for the cloud part.
  enable-ci         Enable continuous-integration systems to build and...
  expand-extensions Display snapcraft.yaml with all extensions applied.
  export-login      Save login configuration for a store account in FILE.
  extension         Show contents of extension.
  gated             Get the list of snaps and revisions gating a snap.
  help              Obtain help for a certain topic, plugin or command.
  init              Initialize a snapcraft project.
  list-extensions   List available extensions.
  list-keys         List the keys available to sign assertions.
  list-plugins      List the available plugins that handle different types...
  list-registered   List snap names registered or shared with you.
  list-revisions    Get the history on the store for <snap-name>.
  login             Login with your Ubuntu One e-mail address and password.
  logout            Clear session credentials.
  pack              Create a snap from a directory holding a valid snap.
  prime             Final copy and preparation for the snap.
  pull              Download or retrieve artifacts defined for a part.
  push              Push <snap-file> to the store.
  push-metadata     Push metadata from <snap-file> to the store.
  register          Register <snap-name> with the store.
  register-key      Register a key with the store to sign assertions.
  release           Release <snap-name> on <revision> to the selected
                    store...
  search            Searches the remote parts cache for matching parts.
  sign-build        Sign a built snap file and assert it using the...
  snap              Create a snap.
  stage             Stage the part's built artifacts into the common...
  status            Get the status on the store for <snap-name>.
  update            Updates the parts listing from the cloud.
  validate          Validate a gated snap.
  version           Obtain snapcraft's version number.
  whoami            Returns your login information relevant to the store.
root@host:~$ 

That's it! Now, let's get info on a snap and then install it;

[root@host ~]# snap info hello-world
name:      hello-world
summary:   The 'hello-world' of snaps
publisher: Canonical✓
contact:   snappy-devel@lists.ubuntu.com
license:   unset
description: |
  This is a simple hello world example.
commands:
  - hello-world.env
  - hello-world.evil
  - hello-world
  - hello-world.sh
snap-id:      buPKUD3TKqCOgLEjjHx5kSiCpIs5cMuQ
tracking:     stable
refresh-date: today at 11:40 EDT
channels:
  stable:    6.4 2019-04-17 (29) 20kB -
  candidate: 6.4 2019-04-17 (29) 20kB -
  beta:      6.4 2019-04-17 (29) 20kB -
  edge:      6.4 2019-04-17 (29) 20kB -
installed:   6.4            (29) 20kB -
[root@host ~]# 

Here's how to install an app using snap:

[root@host ~]# snap install hello-world
hello-world 6.4 from Canonical✓ installed

[root@host ~]# hello-world
Hello World!
[root@host ~]#

Get Started Today!

Still have questions? Our Support Team is standing by with talented individuals who have an intimate knowledge of web hosting technologies, especially those discussed in this article. If you are uncomfortable walking through the steps outlined above, we are here to assist!

Avatar for Justin Palmer

About the Author: Justin Palmer

Justin Palmer is a professional application developer with Liquid Web

Latest Articles

In-place CentOS 7 upgrades

Read Article

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article