在Fedora 30/Fedora 29/28上安装Snapd和Snap应用程序

时间:2020-02-23 14:33:20  来源:igfitidea点击:

在这篇文章中,我们将介绍在Fedora 30和Fedora 29/28上安装和使用Snapd Service的步骤。
Snappy是一种来自Canonical的包管理和软件部署系统。

什么是snap?

snap:是包含应用程序代码的Squashfs文件系统和
snap.yaml包含特定元数据的文件。
它具有只读文件系统,一旦安装,可写的区域。
是独立的。
它捆绑了它所需的大多数库和运行时间,可以在不影响其余系统的情况下更新和恢复,而不是通过安全机制从操作系统和其他应用程序限制,但可以根据细粒度交换内容和功能。
由用户控制的策略和OS默认值。

什么是snapd?

Snapd是一个REST API守护程序服务,它在Linux系统上运行,以管理Snap Packages("Snaps")。
它与Snap Store交互并提供命令客户端 snap用来与它互动。
我们必须在开始管理任何Linux发行版之前安装Snapd。

为什么使用snap?

Snap Packages为每个Linux桌面,服务器,云或者设备的任何应用程序。
SNAPS安装更快,更容易创建,更安全运行,他们自动更新,以便应用程序始终新鲜,从未被打破。
我们可以带来自己的构建基础架构或者使用我们的基础架构。

如何在Fedora 30/29/28上安装和使用Snapd

通过在终端中执行下面的命令在Fedora 30/Fedora 29/28上安装Snapd。

sudo dnf -y install snapd

等待安装完成,然后确认已安装的Snapd版本:

$rpm -qi snapd
Name        : snapd
Version     : 2.36
Release     : 1.fc29
Architecture: x86_64
Install Date: Sat 17 Nov 2016 11:36:34 AM UTC
Group       : System Environment/Base
Size        : 53984174
License     : GPLv3
Signature   : RSA/SHA256, Sun 04 Nov 2016 05:14:04 PM UTC, Key ID a20aa56b429476b4
Source RPM  : snapd-2.36-1.fc29.src.rpm
Build Date  : Sun 04 Nov 2016 05:00:32 PM UTC
Build Host  : buildvm-32.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://github.com/snapcore/snapd
Bug URL     : https://bugz.fedoraproject.org/snapd
Summary     : A transactional software package manager
Description :
Snappy is a modern, cross-distribution, transactional package manager
designed for working with self-contained, immutable packages.

然后启用Snapd Socket:

$sudo systemctl enable --now snapd.socket
Created symlink from /etc/systemd/system/sockets.target.wants/snapd.socket to /usr/lib/systemd/system/snapd.socket.

经典约束需要snap /snap或者符号链接 /snap/var/lib/snapd/snap
为下面创建一个符号链接:

sudo ln -s /var/lib/snapd/snap /snap

Snapd现在已准备好使用。
我们使用snap命令与它交互。
请参阅以下帮助页面:

# snap --help
Usage:
  snap [OPTIONS] <command>
Install, configure, refresh and remove snap packages. Snaps are
'universal' packages that work across many different Linux systems,
enabling secure distribution of the latest apps and utilities for
cloud, servers, desktops and the internet of things.
This is the CLI for snapd, a background service that takes care of
snaps on the system. Start with 'snap list' to see installed snaps.

Application Options:
      --version  Print the version and exit
Help Options:
  -h, --help     Show this help message
Available commands:
  abort       Abort a pending change
  ack         Adds an assertion to the system
  alias       Sets up a manual alias
  aliases     Lists aliases in the system
  buy         Buys a snap
  changes     List system changes
  connect     Connects a plug to a slot
  disable     Disables a snap in the system
  disconnect  Disconnects a plug from a slot
  download    Downloads the given snap
  enable      Enables a snap in the system
  find        Finds packages to install (aliases: search)
  get         Prints configuration options
  help        Help
  info        show detailed information about a snap
  install     Installs a snap to the system
  interface   Lists snap interfaces
  interfaces  Lists interfaces in the system
  known       Shows known assertions of the provided type
  list        List installed snaps
  login       Authenticates on snapd and the store
  logout      Log out of the store
  logs        Retrieve logs of services
  pack        pack the given target dir as a snap
  prefer      Prefer aliases from a snap and disable conflicts
  refresh     Refreshes a snap in the system
  remove      Removes a snap from the system
  restart     Restart services
  revert      Reverts the given snap to the previous state
  run         Run the given snap command
  services    Query the status of services
  set         Changes configuration options
  start       Start services
  stop        Stop services
  switch      Switches snap to a different channel
  tasks       List a change's tasks (aliases: change)
  try         Tests a snap in the system
  unalias     Unalias a manual alias or an entire snap
  version     Shows version details
  watch       Watch a change in progress
  whoami      Prints the email the user is logged in with.

如何在Fedora 30/29/28上安装Snap应用程序

snap命令用于在Snap Store上可用的snap交互。

搜索snap:

搜索snap,使用

$snap find <search terms>

这将查询商店并将结果列出其版本号,开发人员名称和描述。

我将为从Snap Store安装PowerShell的一个例子。

# snap search powershell
Name                Version          Developer             Notes    Summary
powershell-preview  6.2.0-preview.2  microsoft-powershell  classic  PowerShell for every system!
powershell          6.1.1            microsoft-powershell  classic  PowerShell for every system!

通过运行安装Snap:

$sudo dnf install -y icu
$sudo snap install powershell --classic
powershell 6.1.1 from 'microsoft-powershell' installed

等下载完成,应该花费短时间完成。
由于二进制文件位于下面, /snap/bin/我们需要将此添加到 $PATH多变的。

$sudo vim /etc/profile
export PATH="$PATH:/snap/bin/"

源文件以获取新路径

source /etc/profile

通过开始测试 pwsh会议。

# pwsh 
PowerShell 6.1.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /root>

要列出已安装的snap:

# snap list
Name        Version    Rev   Developer             Notes
core        16-2.35.5  5742  canonical             core
node        10.13.0    1266  nodesource            classic
powershell  6.1.1      14    microsoft-powershell  classic

通过运行手动更新snap snap refresh

# snap refresh powershell 
snap "powershell" has no updates available

删除扣篮

要删除Snap,我们需要执行的只是运行。 snap remove <snap name>在我们的案件中,做到:

# snap remove powershell
powershell removed

检查snap信息:

使用命令 snap info检查有关snap包的更多信息。

[Hyman@theitroad ~]# snap info powershell
name:      powershell
summary:   PowerShell for every system!
publisher: microsoft-powershell
contact:   https://github.com/powershell/powershell
description: |
  PowerShell is an automation and configuration management platform.
  It consists of a cross-platform (Windows, Linux, and macOS)
  command-line shell and associated scripting language.
  
  See
  https://docs.microsoft.com/en-us/powershell/scripting/powershell-core-support
  for support details.
snap-id:     JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie
channels:              
  stable:    6.1.1 (8) 59MB classic
  candidate: 6.1.1 (8) 59MB classic
  beta:      6.1.1 (8) 59MB classic
  edge:      6.1.1 (8) 59MB classic

滚回到以前的应用程序

使用 snap revert

$sudo snap revert <snap name>