Creating a Linux snap package for an existing application.

Derrick Sekidde
Crane Cloud
Published in
4 min readFeb 5, 2024

--

Photo by Gabriel Heinzer on Unsplash

We have a Command Line Application that we wanted to increase its usability. Our main focus is ease of installation for different users across different platforms we decided to create a snap package for the Linux users as well as homebrew for Mac users. Here I detail the process for the snap package.

I began by installing the following:

sudo snap install snapcraft --classic
sudo snap install multipass --classic

After installing the above. You can run the following command to test if your installation is successful.

snap --version

Given that I have an already existing application that I want to create a snap package for. A brief about my application is that it is a command line tool. I clone the repository and create a new branch to work with. In the root directory, I go ahead to run the following command in the root directory.

snapcraft init

On success, a new folder called `snap` will be created, and therein a template snapcraft.yml file. It is pre-filled with information you can change.

This is the preliminary snapcraft.yml after for dev mode.

Let me give a brief breakdown of the contents therein:

Name: This is the name of the application, this will also be the name the package is called in the snap store.

Base: This defines a run-time environment with a set of libraries common to most applications, the default(created in the template) is core18 but for my application core20 worked fine, yes core22 didn't work for my application. Goes without saying these are based on Ubuntu versions🫠 guess the correlation with 18, 20, and 22 makes sense now. For more information about these Python plugs here.

Version: Well if you want to version your snap, this is it, and it is required.

Summary: This ought to be a sentence about your application’s purpose.

Description: This is an in-depth detailing of everything your application does or how it can be used and any other details.

Grade: This indicates the level of stability and support your snap provides. Stable which indicates a stable rigorously tested package ready for production. Devel indicates the package is in development and contains experimental features. Edge usually indicates a package intended for testing and usually has the latest features and updates. Beta indicates the package is in the beta stage and may still contain issues and is used to gather feedback from users before a stable release.

Confinement: This means the level of isolation and access restrictions imposed on the snap when it runs on a system. Strict: The most secure level of confinement where the snap is isolated and can only access approved resources. Classic: This offers more freedom, akin to traditional Linux packages, but necessitates special permission and undergoes rigorous review for Snap Store distribution. Devmode: Primarily for development and testing, though unsuitable for stable Snap Store distribution due to security bypasses.

Parts: These are the building blocks of a snap. Each part defines how a component of your application or snap should be obtained, built, and staged. They can be libraries, binaries, or any other components necessary for your snap. — Plugin: this defines a build process and covers different build systems and languages and for our case python given that my application is Python-based. — Source: where to obtain the source code or files for a particular part. It can be a URL to a tarball, a Git repository, a local directory, or other sources supported by Snapcraft. Snapcraft needs to fetch the necessary files to build the snap. In our case, we are building this within the source code hence the dot.

Apps: This defines a section for services and applications provided by the snap package each of which is defined under apps. You can define metadata under it like execution commands, environment variables, plugs, and slots.

`myapplication` defined under apps indicates that this snap package provides an application named myapplication.

Command: The entire line of the command specifies that when myapplication is executed, the executable is located at bin/myapplication within the snap package should be run.

To run my application just type:

snapcraft

This will go ahead to create the snap and it will be named something like “myapplication_1.0_amd64.snap” and to run and test your application run the following command

snap install myapplication_1.0_amd64.snap --devmode

This will go ahead to install my application and being a command line tool I just run it with its command indicated of:

myapplication

With the above my application is able to work perfectly but that is in the development mode.

To remove the installation run:

sudo snap remove myapplication_1.0_amd64.snap

Next, we will look at how to configure it for the production environment and how to get it to the snap store. Check it out here in this article:

--

--