Welcome to the world of snaps! In this tutorial, we are going to cover the very basics on how to use snaps on your Linux distribution, and you'll directly see the main benefits of them in action.
11 |snapd
service on your system.If this looks like a long list to you, you will find that you are going to get through it in a breeze. All of the above is very easy to do thanks to the simplicity of the snap command line interface.
22 |This tutorial is focused on using the snap
command. Some command line tools are provided for you to simply copy and paste.
snapd
is the service which runs on your machine and keeps track of your installed snaps, interacts with the store and provides the snap
command for you to interact with it. Installing it on any of the Linux distributions mentioned below is straight-forward.
$ sudo pacman -S snapd 52 | 53 | # enable the snapd systemd service: 54 | sudo systemctl enable --now snapd.socket55 |
$ sudo apt install snapd57 |
$ sudo dnf copr enable zyga/snapcore 59 | $ sudo dnf install snapd 60 | 61 | # enable the snapd systemd service: 62 | $ sudo systemctl enable --now snapd.service 63 | 64 | # SELinux support is in beta, so currently: 65 | $ sudo setenforce 0 66 | 67 | # to persist, edit /etc/selinux/config to set SELINUX=permissive and reboot.68 |
Install the gentoo-snappy overlay.
70 |Install the snap meta layer.
72 |$ sudo zypper addrepo http://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_42.2/ snappy 74 | $ sudo zypper install snapd75 |
Enable the snap-openwrt feed.
77 |You should already be all set on ubuntu 16.04 LTS desktop. On 14.04, you need to install it though via:
79 |$ sudo apt install snapd80 |
Now that your system is all ready to go, let's install your first snap on it!
81 | 83 | 84 | 85 |snapd
is up and running now, so let's start using it! Here is how you can find any "hello world" kind of snaps in the store:
$ snap find hello 91 | hello-node-snap 1.0.2 bhdouglass - A simple hello world command 92 | hello-mdeslaur 2.10 mdeslaur - GNU Hello, the "hello world" snap 93 | hello-snap 0.01 muhammad - GNU hello-snap, the "Hello, Snap!" snap 94 | hello 2.10 canonical - GNU Hello, the "hello world" snap 95 | hello-world 6.3 canonical - The 'hello-world' of snaps 96 | hello-sergiusens 1.0 sergiusens - hello world example 97 | hello-gabriell 0.1 gabriell - Qt Hello World example 98 | hello-bluet 0.1 bluet - Qt Hello World example 99 | so-hello-world 0.2 shadowen - the old classic 100 | hello-huge 1.0 noise - a really big snap101 |
snap find <search terms>
will query the store and list the results with their version number, developer names and description.
As you can see, a number of developers uploaded snaps related to "hello world". Let's just install one of them.
104 |$ sudo snap install hello 105 | 106 | hello (stable) 2.10 from 'canonical' installed107 | 109 |
To run the command, simply type hello in the command line (which is a command provided by the hello
snap:
$ hello 111 | Hello, world!112 |
This is obviously just a simple example, what it has in common with all other snaps though, is that it runs fully confined and can only access its own data.
113 |See the snaps installed on your system with snap list
, which will also tell you the software version, the unique revision, the developer of the installed snap, and any optional extra information.
$ snap list 116 | Name Version Rev Developer Notes 117 | hello 2.10 20 canonical - 118 | core 16.04.1 423 canonical -119 |
You will note that the core
snap, containing the base snap system is also part of the list. Among other things, it includes a newer snapd, which will make sure you will always be up to date).
The good news is that snaps are updated automatically in the background every day! If you want, you can still get the latest version of all your snaps manually by running snap refresh
. It will bring you completely up to date for all snaps, unless you specify a particular snap to refresh.
$ sudo snap refresh hello 123 | error: cannot refresh "hello": snap "hello" has no updates available 124 | $ sudo snap refresh 125 | core updated 126 | hello 64.75 MB [=====================================>___] 12s 127 |128 |
But these aren't the only features of the snap
command: you can get way more fine-grained in terms of tracking various versions of the same app, depending on how close to current development you want to be. This is all possible thanks to the channel feature! We might delve into this later on.
Our first example was simple and shipped only one command, but in general snap packages can contain more than one command (for example a set of tools shipped in one snap). All commands are then namespaced by the snap package name. Run the steps below to see an example in action:
136 |$ sudo snap install hello-world 137 | 0 B / 20.00 KB [_______________________________________________________] 0.00 % 138 | 139 | hello-world (stable) 6.3 from 'canonical' installed 140 | $ hello-world 141 | Hello World! 142 | $ hello-world.env 143 | < env variables >144 | 146 |
What is a service? A service is simply a long running command, which will ideally always be on or for a definite period of time to answer some requests.
148 |Snaps can also ship system-wide services. If you install the snap package called shout (a self-contained web irc client), you can see this live in action - simply point your browser to http://localhost:9000/ to interact with the service.
149 |Services of snaps are simply started/stopped on system startup and shutdown. They can be configured to be activated on demand as well.
150 |Removing a snap is just a command away, all you need to do is run snap remove <snap name>
. In our case just do:
$ sudo snap remove hello-world 153 | 154 | hello-world removed155 |
Nice and clean, nothing is left-over! Application code, its run time dependencies and associated user data are all cleaned up. If your snap declared a service, they will as well be shut down and removed.
156 | 157 | 158 |Developers can release stable, candidate, beta and edge versions of a snap at the same time, to engage with a community who are willing to test upcoming changes. You decide how close to the leading edge you want to be.
162 |By default, snaps are installed from the stable channel. By convention, developers use the candidate channel to provide a heads-up of a new stable revision, putting it in candidate a few days before stable so that people can test it out. The beta channel is for unfinished but interesting milestones, and the edge channel is conventionally used for regular or daily development builds that have passed some lightweight smoke-testing.
163 |$ sudo snap refresh hello --channel=beta 165 | 166 | hello (beta) 2.10.1 from 'canonical' refreshed167 |
Now, you can run the beta version of the snap and see its output is different:
168 |$ hello 169 | Hello, snap padawan!170 |
snapd
will now track the beta channel of the hello snap and get any updates delivered through it.
One of the features of snapd
is to be able to simply roll back to a previous version of an application (including the data associated with the snap) for any reason:
$ sudo snap revert hello 177 | 178 | hello reverted to 2.10 179 | $ hello 180 | Hello, world!181 |
With this rollback system built-in, you can confidently update knowing that you will always have a way to go back to the previous working state!
182 | 183 | 184 |Congratulations! You made it!
189 |By now you should have found snaps in the store, installed and updated them, changed between channels and much more. The snap command line is designed to be as simple and memorisable as possible. After using it just a couple of times, it should become second nature to you.
190 |Welcome to the world of snaps! In this tutorial, we are going to cover the very basics on how to use snaps on your Linux distribution, and you'll directly see the main benefits of them in action.
11 |snapd
service on your system.If this looks like a long list to you, you will find that you are going to get through it in a breeze. All of the above is very easy to do thanks to the simplicity of the snap command line interface.
21 |This tutorial is focused on using the snap
command. Some command line tools are provided for you to simply copy and paste.
snapd
is the service which runs on your machine and keeps track of your installed snaps, interacts with the store and provides the snap
command for you to interact with it. Installing it on any of the Linux distributions mentioned below is straight-forward.
$ sudo pacman -S snapd 50 | 51 | # enable the snapd systemd service: 52 | sudo systemctl enable --now snapd.socket53 |
$ sudo apt install snapd55 |
$ sudo dnf copr enable zyga/snapcore 57 | $ sudo dnf install snapd 58 | 59 | # enable the snapd systemd service: 60 | $ sudo systemctl enable --now snapd.service 61 | 62 | # SELinux support is in beta, so currently: 63 | $ sudo setenforce 0 64 | 65 | # to persist, edit /etc/selinux/config to set SELINUX=permissive and reboot.66 |
Install the gentoo-snappy overlay.
68 |Install the snap meta layer.
70 |$ sudo zypper addrepo http://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_42.2/ snappy 72 | $ sudo zypper install snapd73 |
Enable the snap-openwrt feed.
75 |You should already be all set on ubuntu 16.04 LTS desktop. On 14.04, you need to install it though via:
77 |$ sudo apt install snapd78 |
Now that your system is all ready to go, let's install your first snap on it!
79 | 81 | 82 | 83 |snapd
is up and running now, so let's start using it! Here is how you can find any "hello world" kind of snaps in the store:
$ snap find hello 89 | hello-node-snap 1.0.2 bhdouglass - A simple hello world command 90 | hello-mdeslaur 2.10 mdeslaur - GNU Hello, the "hello world" snap 91 | hello-snap 0.01 muhammad - GNU hello-snap, the "Hello, Snap!" snap 92 | hello 2.10 canonical - GNU Hello, the "hello world" snap 93 | hello-world 6.3 canonical - The 'hello-world' of snaps 94 | hello-sergiusens 1.0 sergiusens - hello world example 95 | hello-gabriell 0.1 gabriell - Qt Hello World example 96 | hello-bluet 0.1 bluet - Qt Hello World example 97 | so-hello-world 0.2 shadowen - the old classic 98 | hello-huge 1.0 noise - a really big snap99 |
snap find <search terms>
will query the store and list the results with their version number, developer names and description.
As you can see, a number of developers uploaded snaps related to "hello world". Let's just install one of them.
102 |$ sudo snap install hello 103 | 104 | hello (stable) 2.10 from 'canonical' installed105 | 107 |
To run the command, simply type hello in the command line (which is a command provided by the hello
snap:
$ hello 109 | Hello, world!110 |
This is obviously just a simple example, what it has in common with all other snaps though, is that it runs fully confined and can only access its own data.
111 |See the snaps installed on your system with snap list
, which will also tell you the software version, the unique revision, the developer of the installed snap, and any optional extra information.
$ snap list 114 | Name Version Rev Developer Notes 115 | hello 2.10 20 canonical - 116 | core 16.04.1 423 canonical -117 |
You will note that the core
snap, containing the base snap system is also part of the list. Among other things, it includes a newer snapd, which will make sure you will always be up to date).
The good news is that snaps are updated automatically in the background every day! If you want, you can still get the latest version of all your snaps manually by running snap refresh
. It will bring you completely up to date for all snaps, unless you specify a particular snap to refresh.
$ sudo snap refresh hello 121 | error: cannot refresh "hello": snap "hello" has no updates available 122 | $ sudo snap refresh 123 | core updated 124 | hello 64.75 MB [=====================================>___] 12s 125 |126 |
But these aren't the only features of the snap
command: you can get way more fine-grained in terms of tracking various versions of the same app, depending on how close to current development you want to be. This is all possible thanks to the channel feature! We might delve into this later on.
Our first example was simple and shipped only one command, but in general snap packages can contain more than one command (for example a set of tools shipped in one snap). All commands are then namespaced by the snap package name. Run the steps below to see an example in action:
134 |$ sudo snap install hello-world 135 | 0 B / 20.00 KB [_______________________________________________________] 0.00 % 136 | 137 | hello-world (stable) 6.3 from 'canonical' installed 138 | $ hello-world 139 | Hello World! 140 | $ hello-world.env 141 | < env variables >142 | 144 |
What is a service? A service is simply a long running command, which will ideally always be on or for a definite period of time to answer some requests.
146 |Snaps can also ship system-wide services. If you install the snap package called shout (a self-contained web irc client), you can see this live in action - simply point your browser to http://localhost:9000/ to interact with the service.
147 |Services of snaps are simply started/stopped on system startup and shutdown. They can be configured to be activated on demand as well.
148 |Removing a snap is just a command away, all you need to do is run snap remove <snap name>
. In our case just do:
$ sudo snap remove hello-world 151 | 152 | hello-world removed153 |
Nice and clean, nothing is left-over! Application code, its run time dependencies and associated user data are all cleaned up. If your snap declared a service, they will as well be shut down and removed.
154 | 155 | 156 |Developers can release stable, candidate, beta and edge versions of a snap at the same time, to engage with a community who are willing to test upcoming changes. You decide how close to the leading edge you want to be.
160 |By default, snaps are installed from the stable channel. By convention, developers use the candidate channel to provide a heads-up of a new stable revision, putting it in candidate a few days before stable so that people can test it out. The beta channel is for unfinished but interesting milestones, and the edge channel is conventionally used for regular or daily development builds that have passed some lightweight smoke-testing.
161 |$ sudo snap refresh hello --channel=beta 163 | 164 | hello (beta) 2.10.1 from 'canonical' refreshed165 |
Now, you can run the beta version of the snap and see its output is different:
166 |$ hello 167 | Hello, snap padawan!168 |
snapd
will now track the beta channel of the hello snap and get any updates delivered through it.
One of the features of snapd
is to be able to simply roll back to a previous version of an application (including the data associated with the snap) for any reason:
$ sudo snap revert hello 175 | 176 | hello reverted to 2.10 177 | $ hello 178 | Hello, world!179 |
With this rollback system built-in, you can confidently update knowing that you will always have a way to go back to the previous working state!
180 | 181 | 182 |Congratulations! You made it!
187 |By now you should have found snaps in the store, installed and updated them, changed between channels and much more. The snap command line is designed to be as simple and memorisable as possible. After using it just a couple of times, it should become second nature to you.
188 |First step simple content
11 | 12 | 13 |At the top, you saw some medata, here are additional notes to them:
17 |category, corresponding to one of the area of the developer site
27 | 28 | 29 |This is the last step
33 | 34 | 35 |A, local image
11 |A relative image, in upper directory
13 |At the top, you saw some medata, here are additional notes to them:
20 |category, corresponding to one of the area of the developer site
30 | 31 | 32 |This is the last step
36 | 37 | 38 |A local image
11 |Extensions are kept
13 |At the top, you saw some medata, here are additional notes to them:
20 |category, corresponding to one of the area of the developer site
30 | 31 | 32 |This is the last step
36 | 37 | 38 |A remote image in jpg
11 |At the top, you saw some medata, here are additional notes to them:
18 |category, corresponding to one of the area of the developer site
28 | 29 | 30 |This is the last step
34 | 35 | 36 |A remote image
11 |At the top, you saw some medata, here are additional notes to them:
18 |category, corresponding to one of the area of the developer site
28 | 29 | 30 |This is the last step
34 | 35 | 36 |A relative image, in upper directory
11 |At the top, you saw some medata, here are additional notes to them:
18 |category, corresponding to one of the area of the developer site
28 | 29 | 30 |This is the last step
34 | 35 | 36 |A, local image
11 |At the top, you saw some medata, here are additional notes to them:
18 |category, corresponding to one of the area of the developer site
28 | 29 | 30 |This is the last step
34 | 35 | 36 |A local image
11 |A remote image in jpg
13 |A remote image in jpg
15 |A relative image, in upper directory
17 |Extensions are kept
19 |At the top, you saw some medata, here are additional notes to them:
26 |category, corresponding to one of the area of the developer site
36 | 37 | 38 |This is the last step
42 | 43 | 44 |