如何在Linux上使用快照包

The Snap packages icon.
Ubuntu
的Ubuntu

When you install Linux software packages with snap, you can say goodbye to dependency hell and breaking other working applications. Snap packages were originally designed for Ubuntu, but they’re now available on a variety of Linux distributions.

当使用snap安装Linux软件包时,您可以告别依赖地狱并破坏其他可运行的应用程序。 Snap软件包最初是为Ubuntu设计的,但现在可以在各种Linux发行版中使用。

什么是快照包? (What Are Snap Packages?)

In the past, installing applications on Linux was a potentially frustrating experience. You’d install something only to find a particular library or other dependency was missing or outdated. You’d then hunt down the missing resource and install it, only to find another application depended on the version of the library you just replaced. Fix one, break one, repeat.

过去,在Linux上安装应用程序可能会令人沮丧。 您只会安装某些东西来查找特定的库或其他依赖项丢失或过时。 然后,您将寻找丢失的资源并进行安装,只是找到另一个应用程序,该应用程序取决于您刚替换的库的版本。 解决一个,打破一个,重复一次。

This has improved with better package management systems, like apt, dnf, and pacman. However, you still face a struggle if you need different versions of the same application installed. Or, if you use two applications that clash because they’re tied to specific—but different—versions of a library.

有了更好的软件包管理系统(如aptdnfpacman) ,这种情况得到了改善。 但是,如果需要安装同一应用程序的不同版本,则仍会遇到困难。 或者,如果您使用两个冲突的应用程序,因为它们与库的特定(但不同)版本相关联。

One solution to these problems is application packing and deployment systems. Snappy is one of the more popular of these. It’s based on a packaging and deployment system called Click, which harkens back to the Ubuntu Touch initiative. AppImage and FlatPack are others you might have encountered.

解决这些问题的一种方法是应用程序打包和部署系统。 Snappy是其中比较流行的一种。 它基于名为Click的打包和部署系统,该系统可以追溯到Ubuntu Touch计划。 您可能会遇到过AppImageFlatPack

These systems encapsulate the application together with any dependencies and other requirements in a single compressed file. The application then runs in a sort of mini-container. It’s sandboxed and separated from other applications. The libraries and other resources the application is packaged with or requires are only available to it alone.

这些系统将应用程序以及所有依赖关系和其他要求封装在一个压缩文件中。 然后,该应用程序将在一种小型容器中运行。 它已沙盒化,并与其他应用程序分离。 应用程序打包或需要的库和其他资源仅可单独使用。

They aren’t installed in the traditional sense, so they don’t cause any problems with other applications that require different versions of the same resources. You can even install and run applications that need conflicting library versions because each application is in its own sandbox.

它们不是传统意义上的安装,因此对于需要相同资源不同版本的其他应用程序不会造成任何问题。 您甚至可以安装和运行需要冲突库版本的应用程序,因为每个应用程序都在其自己的沙箱中。

If they’re not installed in the usual way, though, how are they handled? Well, the single package file is downloaded, decompressed, and mounted as a SquashFSvirtual file system. It’s then presented to you as a virtual environment. All of this takes place behind the scenes. All you’ll know is you’ve installed an application, and, now, you have access to it.

但是,如果未按常规方式安装它们,该如何处理? 好了,将单个软件包文件下载,解压缩并安装为SquashFS 虚拟文件系统 。 然后将其作为虚拟环境呈现给您。 所有这些都是在幕后进行的。 您只知道已经安装了一个应用程序,现在就可以访问它。

Of course, because each package file must contain every resource the application needs, the package files can be large. It’s also easy to duplicate a resource you’d normally only install once, such as MySQL or Apache. If two different snap applications require the same resources, they each bring their own copy.

当然,由于每个程序包文件都必须包含应用程序所需的每个资源,因此程序包文件可能很大。 复制通常只安装一次的资源也很容易,例如MySQLApache 。 如果两个不同的snap应用程序需要相同的资源,则它们各自带来自己的副本。

This is the trade-off for the simplicity of the install, and the removal of the resource-conflict headaches, though.

但是,这是为了简化安装和消除资源冲突难题的折衷方案。

安装对齐 (Installing snapd)

Snappy was introduced with Ubuntu 16.04, so if you’re running that version or later, you’re already good to go. On our machine, Snappy was installed on Manjaro 18.04, but we had to install it on Fedora 31.

Snappy是Ubuntu 16.04引入的,因此,如果您运行的是该版本或更高版本,则已经很不错了。 在我们的机器上,Snappy已安装在Manjaro 18.04上,但我们必须将其安装在Fedora 31上。

snap is both the name of the package files and the command you use to interact with them. Behind the scenes, the snapd daemon is also the name of the package you have to install if you don’t already have Snappy on your computer.

snap既是软件包文件的名称,也是您与它们进行交互的命令。 在后台,如果您的计算机上没有Snappy,则snapd守护程序也是您必须安装的软件包的名称。

To install snapd on Fedora type the following command:

要在Fedora上安装snapd ,请输入以下命令:

sudo dnf install snapd
The "sudo dnf install snapd" command in a terminal window.

If you need to install it on Manjaro, use these commands:

如果需要将其安装在Manjaro上,请使用以下命令:

sudo pacman -Sy snapd
sudo systemctl enable --now snapd.socket

You can use the snap version command to see the version of the snap client, snapd daemon, and the software series number. The name and release of your Linux distribution and the kernel version will also be displayed for you.

您可以使用snap version命令查看snap客户端, snapd守护程序的版本以及软件系列号。 Linux发行版本的名称和发行版以及内核版本也将为您显示。

Type the following:

输入以下内容:

snap version
The "snap version" command in a terminal window.

安装快照包 (Installing snap Packages)

It’s a pretty straightforward process to install a snap package. You can use snap to look for snap packages, and then install the one you want.

安装snap包是一个非常简单的过程。 您可以使用snap查找snap软件包,然后安装所需的软件包。

We type the following to look for and install the gimp image editor:

我们键入以下内容以查找并安装gimp图像编辑器

snap find gimp
The "snap find gimp" in a terminal window.

snap searches for matches to the search clue “gimp” and returns its findings. It’ll find anything that matches or mentions the search term.

snap搜索与搜索线索“ gimp”的匹配项并返回其发现。 它会找到与搜索词匹配或提及的任何内容。

To install one of the packages, we use the value from the Name column, as shown below:

要安装其中一个软件包,我们使用“ Name列中的值,如下所示:

sudo snap install gimp
The "sudo snap install gimp" command in a terminal window.

As it downloads, the percentage completed figure rises and a progress bar creeps across from the left of the terminal window. When the installation is complete, a message appears (as shown below) telling you the package was installed.

下载时,完成的百分比会上升,并且进度条从终端窗口的左侧穿过。 安装完成后,将显示一条消息(如下所示),告诉您已安装软件包。

A "gimp 2.10.18 from Snapcrafters installed" message in a terminal window.

You can use the df command to check the capacity and usage of the different file systems configured on your Linux computer. If we pipe its output into the grep command and search for “gimp,” we isolate the entry for the package we just installed.

您可以使用df命令来检查 Linux计算机上配置的不同文件系统的容量和使用情况 。 如果将其输出grepgrep命令中并搜索“ gimp” ,则将隔离刚刚安装的软件包的条目

We type the following:

我们输入以下内容:

df | grep gimp
The "df | grep gimp" command in a terminal window.

This shows us the snap package was mounted as though it were a file system. The mount point is in the snap directory here: /snap/gimp/252. The “252” is the release number of this version of gimp.

这向我们显示了快照软件包的安装,就好像它是一个文件系统一样。 挂载点位于以下位置的snap目录中: /snap/gimp/252 。 “ 252”是此版本的gimp的发行版号。

The file system is listed as: /dev/loop18. Loop device files are used to make regular files accessible as block devices. They’re typically used for mounting the file systems in disk images. In this case, they’re mounting the SquashFS filesystem within the snap package. The “18” means this is the 18th /dev/loop device file in use on this Linux computer.

文件系统列为: /dev/loop18 。 循环设备文件用于使常规文件可作为块设备进行访问。 它们通常用于在磁盘映像中挂载文件系统。 在这种情况下,他们SquashFS文件系统装入snap软件包中。 “ 18”表示这是此Linux计算机上正在使用的第18个/dev/loop设备文件。

We can use the df command to quickly check this. We’ll use the – t (type) option to limit the output to SquashFS file types only.

我们可以使用df命令快速检查这一点。 我们将使用– t (类型)选项将输出限制为仅SquashFS文件类型。

We type the following:

我们输入以下内容:

df -t squashfs
The "df -t squashfs" command in a terminal window.

The mounted SquashFS file systems are listed. A /dev/loop device file handles each one, and there are 18 of them.

列出已安装的SquashFS文件系统。 一个/dev/loop设备文件处理每个文件,其中有18个。

SquashFS file systems llisted in a terminal window.

Each file system is mounted on a directory within the /snap directory. However, this doesn’t mean there are 18 different snap packages installed on this computer. This is an Ubuntu distribution, so some snap packages are installed right out of the box, and we’ve just installed another one.

每个文件系统都安装在/snap目录中的目录上。 但是,这并不意味着此计算机上已安装18个不同的snap程序包。 这是一个Ubuntu发行版,所以有些snap包都安装框的右侧出来,我们刚刚安装了一个又一个。

Additionally, when you install snapd, it installs some core snap packages to handle the needs of other snap packages.

此外,在安装snapd ,它会安装一些核心snap软件包来满足其他snap软件包的需求。

We can use the snap list command, as shown below, to list the installed snap packages:

我们可以使用snap list命令(如下所示)列出已安装的snap软件包:

snap list
A snap list in a terminal window.

The output was a little wide, so the end of the listings is shown below.

输出有点宽,因此清单的结尾如下所示。

The end of the snap list output in a terminal window.

Here’s the entire listing:

这是整个清单:

Name                 Version                    Rev   Tracking  Publisher    Notes
core                 16-2.43.3                  8689  stable    canonical*   core
core18               20200124                   1668  stable    canonical*   base
gimp                 2.10.18                    252   stable    snapcrafters -
gnome-3-26-1604      3.26.0.20191114            98    stable/…  canonical*   -
gnome-3-28-1804      3.28.0-16-g27c9498.27c9498 116   stable    canonical*   -
gnome-calculator     3.34.1+git1.d34dc842       544   stable/…  canonical*   -
gnome-characters     v3.32.1+git3.b9120df       399   stable/…  canonical*   -
gnome-logs           3.34.0                     81    stable/…  canonical*   -
gnome-system-monitor 3.32.1-3-g0ea89b4922       127   stable/…  canonical*   -
gtk-common-themes    0.1-28-g1503258            1440  stable/…  canonical*   -

As you can see, there are 10 snap packages installed, not 18. However, these 10 packages have given rise to the 18 SquashFS file systems. The table columns are fairly self-explanatory, but here’s some clarification:

如您所见,安装了10个snap软件包,而不是18个。但是,这10个软件包已经增加到18个SquashFS文件系统。 表列是很容易解释的,但是这里有一些说明:

  • Name: The name of the snap package that was installed.

    名称 :已安装的snap软件包的名称。

  • Version: The version number of the software in the snap package.

    版本snap包中软件的版本号。

  • Rev: The revision number of the snap package.

    Revsnap包的修订号。

  • Tracking: The channel this snap package monitors for updates. There are four:

    跟踪 :此snap程序包监视更新的渠道。 有四个:

    • Stable: The default channel. As its name states, this channel contains the most stable packages.

      稳定:默认通道。 顾名思义,该频道包含最稳定的软件包。

    • Candidate: This channel is less stable, but very close to it because it contains release candidate level software, which is code-complete. It goes through final testing before it’s moved to the stable channel.

      候选:此通道不稳定,但非常接近它,因为它包含候选发布级别的软件,该软件是代码完整的。 在移至稳定通道之前,它会经过最终测试。

    • Beta: This channel is late development-cycle quality, but it’s not guaranteed to be stable.

      Beta:此渠道是开发周期后期的质量,但不能保证稳定。

    • Edge: For early build testers. You shouldn’t use this channel for important work or on a production computer. Here be dragons!

      优势:适用于早期的构建测试人员。 您不应该将此通道用于重要工作或在生产计算机上使用。 这是龙!

    Tracking: The channel this snap package monitors for updates. There are four:

    跟踪 :此snap程序包监视更新的渠道。 有四个:

  • Publisher: The individual, company, or organization that released the snap package. If it was a verified publisher (and your terminal window supports Unicode), you’ll see a green check mark beside the name of the publisher. If it can’t show a check mark, you’ll see an asterisk (*).

    发布者 :发布snap包的个人,公司或组织。 如果它是经过验证的发布者(并且您的终端窗口支持Unicode ),那么您将在发布者名称旁边看到一个绿色的复选标记。 如果它没有显示复选标记,则会显示一个星号( * )。

  • Notes: Any comments or additional information will appear here.

    注意 :任何评论或其他信息将显示在此处。

捕捉通道 (The snap Channels)

You can use the info option to get a description of a snap package.

您可以使用info选项来获取snap包的描述。

To do so, we type the following:

为此,我们键入以下内容:

snap info gtk-common-themes
The "snap info gtk-common-themes" command in a terminal window.

We can see which channel the package is tracking, and the version of the software in the snap packages in each of the four channels. In most circumstances, you should stay on the stable channel.

我们可以在四个通道的每一个中看到软件包正在跟踪哪个通道,以及snap软件包中的软件版本。 在大多数情况下,您应该保持稳定的状态。

A snap package checks four times per day to see whether a newer version of the software is available from the channel it’s watching or “tracking.”  If you want to change the channel a snap package tracks, you can use the refresh and --channel options.

snap程序包每天检查四次,以查看其正在观看或“跟踪”的频道是否有较新版本的软件。 如果要更改snap程序包跟踪的通道,可以使用refresh--channel选项。

To do so, we type the following:

为此,我们键入以下内容:

sudo snap refresh gtk-common-themes --channel=beta
The "sudo snap refresh gtk-common-themes --channel=beta" command in a terminal window.

If a newer version of the software was available it would be installed, but that wasn’t the case here. However, the snap package is now tracking the beta channel. As soon as a new beta version is released, it’s automatically downloaded and upgraded.

如果有较新版本的软件可用,则将安装该软件,但实际情况并非如此。 但是, snap程序包现在正在跟踪beta通道。 新的Beta版本发布后,就会自动下载并升级。

You can use the --list option to check whether updates are available for any of the snap packages installed on your computer.

您可以使用--list选项来检查更新是否可用于计算机上安装的任何snap软件包。

To do so, we type the following:

为此,我们键入以下内容:

sudo snap refresh --list
The "sudo snap refresh --list" command in a terminal window.

You’ll be told if any of the channels the snap packages on your computer are tracking contain newer software versions.

您将被告知计算机上的snap程序包正在跟踪的任何渠道是否包含较新的软件版本。

If a newer version of the software is available, you can use the refresh option, as shown below, to manually force a refresh:

如果有较新版本的软件可用,则可以使用refresh选项(如下所示)来手动强制刷新:

sudo snap refresh gtk-common-themes
The "sudo snap refresh gtk-common-themes" command in a terminal window.

卸下卡扣包装 (Removing a snap Package)

To uninstall a snap package, you can use the remove option, as shown below:

要卸载snap包,可以使用remove选项,如下所示:

sudo snap remove gimp
The "sudo snap remove gimp" command in a terminal window.

快速备忘单 (The snap Cheat Sheet)

Using snap packages is pretty simple, but we’ve compiled a list of some commands that will help you:

使用快照包非常简单,但是我们编译了一些命令列表,这些命令可以帮助您:

  • To search for a package: snap find package_name

    要搜索软件包: snap find package_name

  • To install a package: sudo snap install package_name

    要安装软件包: sudo snap install package_name

  • To see all installed packages: snap list

    要查看所有已安装的软件包: snap list

  • To get information about a single package: snap info package_name

    要获取有关单个软件包的 snap info package_name snap info package_name

  • To change the channel a package tracks for updates: sudo snap refresh package_name --channel=channel_name

    要更改软件包跟踪更新的频道: sudo snap refresh package_name --channel=channel_name

  • To see whether updates are ready for any installed packages: sudo snap refresh --list

    要查看是否已为任何已安装的软件包准备好更新: sudo snap refresh --list

  • To manually update a package: sudo snap refresh package_name

    手动更新软件包: sudo snap refresh package_name

  • To uninstall a package: sudo snap remove package_name

    卸载软件包: sudo snap remove package_name

翻译自: https://www.howtogeek.com/660193/how-to-work-with-snap-packages-on-linux/

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页