Distributing applications on Linux is not always easy. There are a variety of package formats, basic systems, and available libraries, all of which are a headache as distributions are released over and over again. Now, however, we have something simpler: Snap.
Snap is a new way for developers to package their applications, and it brings many advantages over traditional package formats such as. deb,.rpm. Snap is secure, isolated from each other, and host systems use similar apparmor technologies that are cross-platform and self-contained, allowing developers to accurately package the dependencies required by the application. Sandbox isolation also enhances security and allows applications and the entire snap-based system to be rolled back when problems arise. Snap is really the future of Linux application packaging.
Creating a snap package is not difficult. First, you need a snap base runtime environment that allows your desktop environment to recognize and run the snap package, a tool called SNAPD, which is built into all Ubuntu 16.04 systems by default. Then you need to create the Snap tool Snapcraft, which can be installed with a simple command:
$ sudo apt-get install Snapcraft
The environment is ready to snap when it's installed.
Snap uses a specific YAML format for file Snapcraft.yaml, which defines how the application is packaged and the dependencies it needs. With a simple application to demonstrate, the following YAML file is a practical example of how to snap a Moon-buggy game, which is provided in the Ubuntu source.
The code is as follows:
Name:moon-buggy
version:1.0.51.11
Summary:drive a car across the moon
Description: |
A simple command-line game where your drive a buggy on the moon
Apps
Play
Command:usr/games/moon-buggy
Parts
Moon-buggy:
Plugin:nil
Stage-packages: [Moon-buggy]
Snap
–usr/games/moon-buggy
The code above shows several new concepts. The first part is about how to get the information that your application can find in the store, setting the package's metadata name, version number, summary, and description. The Apps section implements the play command, pointing to the location of the Moon-buggy executable file. The parts section tells Snapcraft the Plug-ins needed to build the application and the dependent packages. All we need in this simple example is the Moon-buggy application itself from the Ubuntu source, Snapcraft is responsible for the rest of the work.
Running Snapcraft in your Snapcraft.yaml directory creates MOON-BUGGY1.0.51.11AMD64.SNAP packages that you can install using the following command:
The code is as follows:
$ snap Install Moon-buggy_1.0.51.11_amd64.snap