如何在 Arch Linux 中启用 Snap 支持
Snap
![](/data/attachment/album/202210/21/100128gzzqkf3fcg3f6q3n.jpg)


Snap 是由 Ubuntu 的母公司 Canonical 设计的通用包格式。有些人不喜欢 Snap，但它有一些优势。


通常，某些应用仅以 Snap 格式提供。这为你提供了在 Arch Linux 中启用 Snap 的充分理由。


我知道 AUR 拥有大量应用，但 Snap 应用通常直接来自开发人员。


如果你希望能够在 Arch Linux 中安装 Snap 应用，你需要先启用 Snap 支持。


有两种方法可以做到：


* 使用 AUR 助手启用 Snap 支持（更简单）
* 通过从 AUR 获取包，手动启用 Snap 支持


让我们看看怎么做。


### 方法 1、使用 AUR 助手启用 Snap


Snap 支持在 Arch 用户仓库中以 `snapd` 包的形式提供。你可以使用 AUR 助手轻松安装它。


有 [许多 AUR 助手](https://itsfoss.com/best-aur-helpers/)，但 `yay` 是我更喜欢的，因为它的语法类似于 [pacman 命令](https://itsfoss.com/pacman-command/)。


如果你还没有安装 AUR，请使用以下命令安装 Yay（需要事先安装 `git`）：



```
git clone https://aur.archlinux.org/yay

cd yay

makepkg -si

```

![安装 yay](/data/attachment/album/202210/21/100130o26mmzniv62o96on.png)


现在 `yay` 已安装，你可以通过以下方式安装 `snapd`：



```
yay -Sy snapd

```

![使用 yay 从 AUR 安装 snapd](/data/attachment/album/202210/21/100130gjp8yhnd8wykkk8s.png)


每当你 [更新 Arch Linux](https://itsfoss.com/update-arch-linux/) 系统时，`yay` 都会启用 `snapd` 的自动更新。


#### 验证 Snap 支持是否有效


要测试 Snap 支持是否正常工作，请安装并运行 `hello-world` Snap 包。



```
sudo snap install hello-world

hello-world
（或者）
sudo snap run hello-world

```

![hello-world Snap 包执行](/data/attachment/album/202210/21/100130afak0044qtst72zx.png)


如果它运行良好，那么你可以轻松安装其他 Snap 包。


### 方法 2、从 AUR 手动构建 snapd 包


如果你不想使用 AUR 助手，你仍然可以从 AUR 获取 `snapd`。让我展示详细的过程。


你需要先安装一些构建工具。



```
sudo pacman -Sy git go go-tools python-docutils

```

![为 Snap 安装依赖项](/data/attachment/album/202210/21/100131l6m344g7ny39r6nt.png)


完成依赖项安装后，现在可以克隆 `snapd` 的 AUR 目录，如下所示：



```
git clone https://aur.archlinux.org/snapd

cd snapd

```

![克隆仓库](/data/attachment/album/202210/21/100131e2o0s2xvx86n7l2x.png)


然后构建 `snapd` 包：



```
makepkg -si

```

当它要求安装其他依赖包时输入 `yes`。


![手动构建 snapd](/data/attachment/album/202210/21/100131h2kqfbtpjf9usnqa.png)


你已安装 `snapd` 守护程序。但是，需要启用它以在启动时自动启动。



```
sudo systemctl enable snapd --now

sudo systemctl enable snapd.apparmor --now #start snap applications

sudo ln -s /var/lib/snapd/snap /snap #optional: classic snap support

```

![启动时启用 Snap](/data/attachment/album/202210/21/100132m3qs3443z33022q2.png)


手动构建包的主要缺点是每次新更新启动时你都必须手动构建。使用 AUR 助手为我们解决了这个问题。


### 总结


我更喜欢 Arch Linux 中的 pacman 和 AUR。很少能看到不在 AUR 中但以其他格式提供的应用。尽管如此，在某些你希望直接从源获取它的情况下，使用 Snap 可能是有利的，例如 [在 Arch 上安装 Spotify](https://itsfoss.com/install-spotify-arch/)。


希望本教程对你有所帮助。如果你有任何问题，请告诉我。




---


via: <https://itsfoss.com/install-snap-arch-linux/>


作者：[Pranav Krishna](https://itsfoss.com/author/pranav/) 选题：[lkxed](https://github.com/lkxed) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Snap is a universal package format designed by Canonical, the parent company of Ubuntu. Some people do not like Snap, but it has some advantages.

Often, some applications are only available in the Snap format. This gives you a good enough reason to enable snap in Arch Linux.

I know that AUR has a vast collection of applications but the snap apps often come directly from the developers.

If you want to be able to install Snap applications in Arch Linux, you need to enable snap support first.

There are two ways to do it:

- Enable Snap support using an AUR helper (easier)
- Enable Snap support manually by getting the packages from AUR

Let’s see how to do it.

## Method 1. Use an AUR helper to enable Snap

Snap is available in the Arch User Repository as the *snapd* package. You can install it easily using an AUR helper.

There are [many AUR helpers](https://itsfoss.com/best-aur-helpers/) out there, but *yay* is what I prefer because it has syntax similar to the [pacman command](https://itsfoss.com/pacman-command/).

If you don’t have an AUR installed already, install Yay using the command below (needs git beforehand):

```
git clone https://aur.archlinux.org/yay
cd yay
makepkg -si
```


Now that *yay* is installed, you can install snapd by:

`yay -Sy snapd`


Yay enables automatic updating of snapd whenever you [update your Arch Linux](https://itsfoss.com/update-arch-linux/) system.

## Verify that snap works

To test if snap works fine, install and run the *hello-world* snap package.

```
sudo snap install hello-world
hello-world
(or)
sudo snap run hello-world
```


If it runs fine, then you can install other snap packages easily.

## Method 2. Manually build the snap package from AUR

If you do not want to use an AUR helper, you can still get the snapd from the AUR. Let me show the detailed procedure.

You will need to install some build tools first.

`sudo pacman -Sy git go go-tools python-docutils`


Once you’re done with installing the dependencies, now you can clone the AUR directory, which goes as:

```
git clone https://aur.archlinux.org/snapd
cd snapd
```


Then make the snapd package:

`makepkg -si`


Enter yes when it asks to install other dependency packages.

![snapd manual install makepkg](https://itsfoss.com/content/images/wordpress/2022/10/snapd-manual-install-makepkg-800x460.png)

You have installed the snapd daemon. However, it needs to be enabled to auto start at boot time.

```
sudo systemctl enable snapd --now
sudo systemctl enable snapd.apparmor --now #start snap applications
sudo ln -s /var/lib/snapd/snap /snap #optional: classic snap support
```


The major disadvantage of manually building a package is that you have to manually build every time a new update kicks in. Using an AUR helper solves that problem for us.

## Conclusion

I prefer pacman and AUR in Arch Linux. It’s rare to see an application that is not in AUR but available in some other formats. Still, using snap could be advantageous in some conditions where you want it directly from the source, like [installing Spotify on Arch](https://itsfoss.com/install-spotify-arch/) for example.

I hope you find this tutorial helpful. Let me know if you have any questions.