Install Snap app to Ubuntu 16.4 desktop system

Source: Internet
Author: User
Tags imagemagick

Canonical company released a new 16.04 system in the last April 2016, and this system is long term support-lts. It supports the Debian installation package as always, but it also supports the latest snap installation package. The snap installation package is the format of an installation package that canonical company recently released. More information can be found on our official developer website: https://developer.ubuntu.com/en/desktop/or http://snapcraft.io/.


1) 16.04 Desktop support


From the above figure, we can see that in 16.04 of the desktop supports two types of installation packages:snap and Debian. In addition, we can see that each application installed by the snap package is self-contained: contains any dependencies (dependencies) required for the application to run, and we can see that each application is isolated from each other. Compared to the Debian package, we can see that each Debian application's installation relies on the installation of other packages, that the Debian application can access each other to create security problems, and that removing one of the Debian applications may cause other applications not to function properly. In contrast, different snap applications can install different versions of the same software (such as one that installs Python 2.7, another app installs Python 3.3) without causing any interference. Theoretically, a snap application can be installed on any Linux distribution because it does not depend on the operating system and its release version. This is very good for the maintenance of the application.

Canonical is currently porting applications to the entire community as snap packs and eventually turning the operating system into an Ubuntu core system to create the safest operating system and good application maintenance.


2) Installation
To enable the snap application to run on a 16.04 system, we have to do some installation. Enter in our terminal:
$ sudo apt update$ sudo apt install snapd$ sudo apt install snapcraft

In our 16.04 system, we have to open universe so that we can install the Snapcraft tool in future development. Snapcraft is a necessary tool for us to compile a snap project, although it is not required at run time. It is located in the Universe channel shown.


Then you can install and use one of the applications we need in our terminal:
$ sudo snap install ubuntu-calculator-app$ ubuntu-calculator-app.calculator

We can run our installed applications directly in the dash of our computer:




If you want to install more apps, you can install them directly to our desktop App Store:


From the above we can see that the Calculator application is also in the inside. If you want to know how this application is implemented, please refer to the source code:
Https://code.launchpad.net/~dpm/ubuntu-calendar-app/snap-all-things

Careful developers may find that the app is actually using the same code as the Ubuntu phone. Did not make any changes. In a sense, Ubuntu really achieves a true fusion (Convergence) application design. On the other hand, this snap application time can be deployed to any Linux distribution, as long as it supports snap packages, and it will not depend on the OS version release. Maintainability should be very good.
How do we use the command line to find the snap application we need?
[Email protected]:~$ snap Find calculatorname                   Version    Developer      Notes  Summaryubuntu-calculator-app  2.1+snap3  Ubuntucoredev  -      Ubuntu Calculator application for the Unity 7 desktop

We can use the above command to find the application in the store with the name containing calculator. We can find all the snap applications released in the store using the following command:
[Email protected]:~$ snap Find Name                       Version                    Developer             Notes    Summaryab                         1.0                        snappy-test           -        Test snap with shortest nameag-mcphail                 1.0.1                      njmcphail             -the        Silver Searcher-mcphail ' s build and upstream git versionalsa-utils                 1.1.0-1                    Woodrow               -        Utilities for configuring and using Alsaapktool                    2.1.1                      ligboy                -        A tool for reverse engineering 3rd party, closed, binary Android apps ....

Of course, we can also find the application we need by the following methods:
[Email protected]:~$ snap Find | grep Hellohello                      2.10                       canonical             -        GNU Hello, the "Hello World" Snaphello-bluet                0.1                        Bluet                 -        Qt Hello World Examplehello-huge                 1.0                        Noise                 -        a really big snaphello-snap                 0.01                       Muhammad              -        GNU hello-snap, the "Hello, snap!" snap

3) Delete a snap app
Just now we have successfully installed a snap application to our desktop system. We can now delete the app with the following command. We'll start by displaying the apps that have been installed on the command line:
[Email protected]:~$ snap listname                   Version               Rev  Developer      noteshello-world            6.1   Canonical      -rssreader              1.0                   x1                  Devmoderssreader-app          1.0                   x2                  -snaptest               1                     X1                  Devmodesnaptest-app           1                     x3                  devmodeubuntu-calculator-app  2.1+snap3             5    Ubuntucoredev  -ubuntu-core            16.04+20160531.11-56  122  canonical      -webcam-webui           1                     X1                  -

Above, we see that the Ubuntu-calculator-app application has been installed. We can delete it by using the following method.
[Email protected]:~$ sudo snap remove Ubuntu-calculator-app[sudo] password for Liuxg:done

To re-display the list of SNAP apps we've installed:
[Email protected]:~$ snap listname           Version               Rev  Developer  noteshello-world    6.1   Canonical  -rssreader      1.0                   x1              Devmoderssreader-app  1.0                   x2              -snaptest       1                     X1              Devmodesnaptest-app   1                     x3              devmodeubuntu-core    16.04+20160531.11-56  122  Canonical  -webcam-webui   1                     
Obviously we can no longer find the Ubuntu-calculator-app application.

4) Where to find the installed files
When we apply an application to our system, we can view all of the snap applications installed in our system with the following commands:
[Email protected]:~$ snap listname                   Version               Rev  Developer      noteshello-world            6.1   Canonical      -rssreader              1.0                   x1                  Devmoderssreader-app          1.0                   x2                  -snaptest               1                     X1                  Devmodesnaptest-app           1                     x3                  devmodeubuntu-calculator-app  2.1+snap3             5    Ubuntucoredev  -ubuntu-core            16.04+20160531.11-56  122  canonical      -webcam-webui           1                     X1                  -

Some of the commands for snap may be unfamiliar to some developers. We can get help with the following methods:
$ snap--help      # Or use "snap <command>--help ' for help" on a specific command

After installing our application, we can find our snap installation file in the following path:
[Email protected]:/var/lib/snapd/snaps$ lshello-world_26.snap    rssreader_x1.snap     snaptest-app_x3.snap          ubuntu-core_122.snaprssreader-app_x1.snap  snaptest-app_x1.snap  snaptest_x1.snap              webcam-webui_ X1.snaprssreader-app_x2.snap  Snaptest-app_x2.snap  ubuntu-calculator-app_5.snap

We can look at mount in the system in the following ways:
[Email protected]:~$ Mount | grep calculator/var/lib/snapd/snaps/ubuntu-calculator-app_5.snap ON/SNAP/UBUNTU-CALCULATOR-APP/5 type SQUASHFS (RO, Relatime)

As we can see from the above, we are actually putting the/var/lib/snapd/snaps/ubuntu-calculator-app_5.snap file through the Mount method so that it can be/snap/ Can be seen in the UBUNTU-CALCULATOR-APP/5 directory. In general, after a snap application is successfully installed, it is located in the/snap/$name/$version/directory.
[Email protected]:/snap/ubuntu-calculator-app/5$ tree-l 2.├──bin│└──calculator├──build│└──ubuntu-calculator-app ├──command-calculator.wrapper├──etc│├──apparmor.d│├──dbus-1│├──default│├──drirc│├──fonts│├──gps. Conf│├──gss│├──init│├──init.d│├──ldap│├──pki│├──pulse│├──ucf.conf│├──x11│└──xdg├──lib │├──systemd│└──x86_64-linux-gnu├──meta│├──gui│└──snap.yaml├──usr│├──bin│├──lib│└──share└──v AR    └──lib

The attentive reader may have found that the files in the Mount directory are like the other Linux installation file structure. It actually installs all the required files needed for this calculator into the same root directory, freeing up any need for system files. In theory, our application does not cause a situation that cannot be run because of a system upgrade or version change. This for some software developers is undoubtedly a huge positive! We have designed the software today, when Ubuntu upgrade to 20.4, we do not need to make any changes. Of course, we can also deploy our application to any other Linux distribution, and it can run very well. We don't need to consider what version of the Linux system it is running on and what version of the release it is.
Of course, for a snap application, the size of the snap file package is also very large.
-rw-r--r--  1 liuxg liuxg 122M July  ubuntu-calculator-app_2.1+snap3_amd64.snap

As can be seen from the above, the size of our snap packet is up to 122M. If we want to view the contents of our package, we can do so by the following command:
$ unsquashfs-l Ubuntu-calculator-app_2.1+snap3_amd64.snap | Less
squashfs-rootsquashfs-root/binsquashfs-root/bin/calculatorsquashfs-root/ command-calculator.wrappersquashfs-root/etcsquashfs-root/etc/x11squashfs-root/etc/x11/xresetsquashfs-root/etc/ x11/xreset.dsquashfs-root/etc/x11/xreset.d/readmesquashfs-root/etc/x11/xresourcessquashfs-root/etc/x11/ xresources/x11-commonsquashfs-root/etc/x11/xsessionsquashfs-root/etc/x11/xsession.dsquashfs-root/etc/x11/ xsession.d/20x11-common_process-argssquashfs-root/etc/x11/xsession.d/30x11-common_xresourcessquashfs-root/etc/ x11/xsession.d/35x11-common_xhost-localsquashfs-root/etc/x11/xsession.d/40x11-common_xsessionrcsquashfs-root/ Etc/x11/xsession.d/50x11-common_determine-startupsquashfs-root/etc/x11/xsession.d/60x11-common_ Localhostsquashfs-root/etc/x11/xsession.d/60x11-common_xdg_path ...

We can also get all the files in the snap package directly via the following command:
$ UNSQUASHFS ubuntu-calculator-app_2.1+snap3_amd64.snap$ CD CD squashfs-root# Hack Hack hack$ snapcraft Snap

We can repackage our app by the last named Snapcraft snap.
Let's take a look at the amount of space our installed applications occupy:

375m./ubuntu-calculator-app/

That is, the size of the space after an app is installed is 350M. Of course, this also depends on the type of application we have installed. For our Ubuntu-calculator-app, we put in the package the QT library we need and everything else it needs. The same is true for any other Python application, and we can put any library needed for the Python version into our package. There is no need to worry about whether it will have any effect on other applications.

5) Publish our app to the store
We can easily publish our already developed apps to our App Store via "My apps". When uploading our app, we must remember to select " Ubuntu Core"As a store to upload.



In order to upload a new snap app to the store, we just need to fill in the metadata information we needed and upload the snap file we developed:




6) Restricted Snap application

When a snap application is installed, it is placed in a restricted, secure sandbox at run time, and each application is isolated from each other. By default, each app in a snap package can access each other and work together. However, if it accesses other applications or other resources that are not in its own package, it will be restricted.
The technology to implement this security sandbox is called Apparmor,seccomp and device cgroups. Each application has its own/tmp directory, devpts and so on. This restricted setting is defined by a project file called Snapcraft.yaml. In this file, snap affirms the resources it wants to access, and the system will produce the appropriate restrictions for it. For a detailed introduction of SNAPCRAFT.YAML, we will introduce it in a later article.
As an example, when we use Snapcraft to produce the snap file we want, we want our snap app to eventually have access to our user's $home file directory. In the snap system, we implement a concept called Plug and slots. We can view the plug and slots that we already exist by following the commands below.
[Email protected]:~$ snap interfacesslot                 plug:camera              -:cups-control        -:firewall-control    -: Gsettings           -:home                rssreader-app,snaptest-app:locale-control      -:log-observe         -:modem-manager       - : Mount-observe       -:network             -:network-bind        webcam-webui:network-control     -:network-manager     -:network-observe     -:opengl              rssreader-app,snaptest-app,ubuntu-calculator-app:optical-drive       -:p pp                 -:p ulseaudio          -:snapd-control       -:system-observe      -:timeserver-control  -: Timezone-control    -:unity7              rssreader-app,snaptest-app,ubuntu-calculator-app:x11                 -

The above shows the plug defined for each snap application in My Computer system. A more detailed introduction to Interfaces can be found in our documentation "Interfaces". In the article, it describes each plugs in detail. When our application needs access to the resources we need, in our Snapcraft.yaml project file, we must declare this permission so that our app can access the resources we need. For example, for our snap, if we want to access the $home directory, we can define it in Snapcraft.yaml:
Name:fooapps:  bar:    Command:bin/bar    

This allows our snap application to access the $home directory. Otherwise, we might find it in the/var/log/syslog file. deniedError message. More information on security can be found in the article "SNAP Security Policy and sandboxing".
In addition, it is worth noting that: If we want our app to be the same as the one we used to run on Ubuntu desktop without being restricted by snap security, we can use the following command to install our app:
$ sudo snap install <package.snap>--devmode

As noted above, this is a development under developer mode. It lets developers open up security issues (unrestricted) when they start developing applications. When you publish your app, we'll debug it safely. For more information on this, we can refer to the article "Learn to make a snap".

About Snapcraft.yaml knowledge, we will in the later chapters in detail, so we do not worry first!

7) How to get snap help
As we have written above, we can get the help of snap with the following command:
[email protected]:~$ snap--helpusage:snap [OPTIONS] <command>the snap tool interacts with the SNAPD daemon T o Control the Snappy software platform. Application options:--version print the version and EXITHELP options:-H,--help Show this help Messageavailab Le Commands:abort abort a pending change Ack Adds a assertion to the system change List a Chang E ' s tasks changes List system changes connect connects a plug to a slot Create-user creates a local system u      Ser disconnect disconnects a plug from a slots find Finds packages to install Help help install Install a snap to the system interfaces Lists interfaces in the system known shows known assertions of the Prov IDed Type list installed snaps login authenticates on SNAPD and the store logout Log out of T       He store refresh refresh a snap in the system remove remove a snap from the system run   Run the given snap command try try a unpacked snap in the system 

For each of the commands below the snap, we can get its help information in the following ways:
[Email protected]:~$ snap install-husage:  snap [OPTIONS] install [install-options] <snap>the Install command i Nstalls the named snap in the system. Application options:      --version        Print the version and EXITHELP options:  -H,--help Show this help           message [Install command options]          --channel= Use this   channel instead of stable          --edge       install from the Edge channel          --beta       Install From the Beta channel          --candidate  install from the candidate channel          --stable     install from the Stable channel          --devmode    Install the snap with non-enforcing security

With the above method, we can have a deeper understanding of the snap command.
7) such as compiling a snap application
If you already have a snap project, you just need to:
    • Install Snapcraft. See the beginning of the article
    • In the root directory of the project, type "Snapcraft" directly. The root directory of the project usually contains a snapcraft.yaml file or a . Snapcraft.yaml file.
Canonical has called on many global developers to develop snap applications. We have already put the developed applications in the following warehouses. If you are interested in this, please install the following instructions to download these applications as a reference:
$ git clone https://github.com/ubuntu/snappy-playpen.git$ CD Snappy-playpen

At present, the following items are available for our reference:
atom/               idea/                openttd/         tinyproxy/cloudfoundry-cli/   imagemagick-edge/    plank/           tyrant-unleashed-optimizer/consul/             imagemagick-stable/  qcomicbook/      ubuntu-clock-app/dcos-cli/           keepassx/            qdriverstation/  ubuntukylin-icon-theme/deis-workflow-cli/  kpcli/               ristretto/       vault/dosbox/             leafpad/             scummvm/         vlc/ffmpeg/             minetest/            shotwell/        wallpaperdownloader/galculator/         moon-buggy/          smplayer/        youtube-dl/gitter-im/          mpv/                 snap-template/heroku/             openjdk-demo/        snaptest/

We can go directly to the root of the project and type the following commands:
$ snapcraft
After the project has been successfully compiled, we can find a file with a. snap extension directly under the project's root directory. This is the snap installation file we need. We can install this file by referring to the method we described above.

If you are interested in how to develop an Ubuntu desktop app, you can refer to my article "How to Package a qmake Ubuntu mobile app as a snap app".
8) How to run a snap app
We can run our app in dash, and we can launch our app from the command line in terminal. When we design our snap applications, we usually use a name called Snapcraft. YAML's project file. Let's use an example to illustrate:
Snapcraft.yaml
Name:snaptest-appversion:1summary:this is a summarydescription:this is the descriptionconfinement:devmodeapps:test:    Command:desktop-launch $SNAP/lib/x86_64-linux-gnu/bin/snaptest plugs: [home,unity7,opengl]parts:application: Source:./src plugin:qmake qt-version:qt5 build-packages:-Cmake-gettext-intltool-ub Untu-touch-sounds-suru-icon-theme-qml-module-qttest-qml-module-qtsysteminfo-qml-module-qt-labs -settings-qtdeclarative5-u1db1.0-qtdeclarative5-qtmultimedia-plugin-qtdeclarative5-qtpositioning-plug In-qtdeclarative5-ubuntu-content1-qt5-default-qtbase5-dev-qtdeclarative5-dev-qtdeclarat    Ive5-dev-tools-qtdeclarative5-folderlistmodel-plugin-qtdeclarative5-ubuntu-ui-toolkit-plugin-xvfb Stage-packages:-ubuntu-sdk-libs-qtubuntu-desktop-qml-module-qtsysteminfo snap:--usr/share/d  OC--usr/include  After: [DESKTOP/QT5] 

In the Snapcraft.yaml file above, the name of our package is called " Snaptest-app". An application defined under apps is called " Test". So on the command line, we can run our final application in the following way:
$ snaptest-app.test

In other words, we can start our application with <<package-name>>.<<application-name>>.
More learning resources can be found at our link address:
    • Https://github.com/snapcore/snapcraft/tree/master/docs
    • https://developer.ubuntu.com/en/desktop/
    • https://developer.ubuntu.com/en/snappy/
    • http://snapcraft.io/


Install Snap app to Ubuntu 16.4 desktop system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.