使用 AppImage 进行 Linux 软件包管理
AppImage 软件包

> 
> AppImage 在自足的环境中分发应用, 它适用于任何 Linux 发行版。
> 
> 
> 


![](/data/attachment/album/202006/15/140050aazux37axew7e0xk.jpg)


管理 Linux 机器（尤其是远程机器）的一个重要分就是管理和安装软件。当本地应用程序出现问题时，或者文件系统上的某些文件损坏需要修复时，你通常会希望推送更新，而不必走很多路坐在物理屏幕前。正如我在 Pluralsight 课程《[Linux 系统维护和故障排除](https://pluralsight.pxf.io/VMKQj)》中所解释的那样，许多问题当然可以通过 Bash 脚本解决，但是仍有很多情况下，除了老式的二进制文件外，没有其他选择。


想象一下，你的某些远程系统需要安装新的应用程序，这样使用这些计算机的团队成员就能够执行某些业务。能够利用 Debian 或 RPM 之类的主要 Linux 仓库系统的集成和自动化，可以使你的管理任务变得更加容易。


正如 Linus Torvalds 永不厌倦地提醒我们的那样，太多的 Linux 软件管理系统的问题是 [Linux 软件管理系统太多了](https://itsfoss.com/desktop-linux-torvalds/)。多年来，应用开发甚至是 Linux 的采用都变得愈加复杂起来，因为你为了提供你的软件（比如，放到 Debian 仓库）而投入的所有时间和工作，对于你想让它们进入 RPM 系统并没有什么帮助，对于 SUSE 的 Zypper 管理器也一样，没有什么帮助。


解决软件孤岛问题的一种有前途的方案是分发具有自足环境的应用，它们可以在任何 Linux 发行版上运行。在这个年轻且不断发展的领域中，选择之一是 [AppImage](https://appimage.org/)。


### 使用 AppImage


我全面投入到了 AppImage。就像我提到的其他软件包管理系统一样，如果你需要的话，有很多复杂的功能可以使用。但是，从本质上讲，AppImage 非常简单。AppImage 不像大多数其他包管理器一样通过仓库工作，它使用单个、独立的文件，可以直接发送或通过网站共享。


下面是个展示它的美妙之处的例子。当我在用 AppImage 时，我在一个技术论坛上看到了一个很老的讨论，它让我找到了一个同样久远且废弃的 GitHub 项目以及相关的 YAML 和配方文件。它们旨在自动构建准备生成 AppImage 包所需的相当复杂的基础架构。尽管该基础架构全部是在 5 年前的 Ubuntu 版本上构建的，但是当我将它们放在一起并运行 `appimagetool` 命令时，它创建了一个 AppImage 文件，它可在我当前的桌面上无缝运行。我不认为有很多有五年历史的 GitHub 复杂项目可以使用其他技术运行，而无需认真重做。


但是这里我我不会介绍这个案例。相反，我将用一个简单的 Hello World 程序向你展示它是如何工作的。首先，请确保本地已安装 AppStream 包。


对于基于 Debian 的系统，运行：



```
$ sudo apt install appstream

```

对于 RPM 系统，请使用：



```
$ sudo dnf install appstream

```

克隆[这篇文章](https://www.booleanworld.com/creating-linux-apps-run-anywhere-appimage/)中提及的 Git 仓库，我会基于它示例：



```
$ git clone <https://github.com/boolean-world/appimage-resources>
$ cd appimage-resources
$ ls hello-world-appimage

```

接下来，使用 `cd` 进入 Git 新创建的目录。这里有两个目录。请使用 `hello-world-appimage`。另一个是更复杂的项目，你也应该考虑尝试一下。


Linux GUI 系统会读取 `helloworld.desktop` 文件来知道如何呈现桌面图标。事实证明，当前的这个文件会在以后给你带来点麻烦，因此请进行一些小修改：添加 `Categories=` 这行并为其赋予值 `GNOME`。不要忘记最后的分号：



```
$ nano hello-world-appimage/helloworld.desktop
        add Categories=GNOME;

```

从 [AppImage GitHub 项目](https://github.com/AppImage/AppImageKit/releases)下载 `appimagetool` 预编译的二进制文件。访问 GitHub 的原因之一：那里有很多出色的文档和资源。下载二进制文件后，使文件可执行，并将 `hello-world-appimage` 目录传给它。但是首先，你需要告诉它你想要的架构。由于某些原因，一个名字以 x86\_64 结尾的工具都不能自行确定是否该使用 x86\_64 来构建应用程序（我不知道这是怎么回事）。



```
$ wget <https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage>
$ chmod +x appimagetool-x86_64.AppImage
$ ARCH=x86_64 ./appimagetool-x86_64.AppImage hello-world-appimage

```

如果你没有看到任何错误消息，那么表示完成了，请运行：



```
$ ls
$ ./hello-world-appimage-x86_64.AppImage

```

### 总结


AppImage 是软件包管理的非常有效的选择。当你探索它时，我想你会发现它是 Linux 发行版默认软件包系统的很好的替代品。




---


via: <https://opensource.com/article/20/6/appimages>


作者：[David Clinton](https://opensource.com/users/dbclinton) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


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


OK
A big part of administrating Linux machines—especially remote machines—is managing and installing software. When something goes wrong with a local application or when something on the filesystem breaks and needs fixing, you're often going to want to push updates without having to travel many miles to sit down in front of a physical screen. As I explain in my Pluralsight course [Linux system maintenance and troubleshooting](https://pluralsight.pxf.io/VMKQj), a lot of problems can be solved through Bash scripts of course, but there are still plenty of cases where there's no alternative to a good, old fashioned binary.

Imagine that some of your remote systems need new applications installed, so the team members using those computers will be able to perform some business function. Being able to leverage the integration and automation of one of the major Linux repository systems—like Debian or RPM—can make your administration tasks a whole lot easier.

As Linus Torvalds never tires of reminding us, the problem with many Linux software management systems is that there are [too many Linux software management systems](https://itsfoss.com/desktop-linux-torvalds/). Over the years, app development and even Linux adoption have been complicated by the fact that all the time and work you invest in preparing your software for, say, Debian repos, won't help you if you want to get them into RPM systems. And neither will help for SUSE's Zypper manager.

One promising solution to the software silo problem is to distribute applications with their own self-contained environments that'll work on any Linux distribution. One option of a standard in this young and growing field is [AppImage](https://appimage.org/).

## Working with AppImages


I'm all-in on AppImage. Like the other package management systems I've mentioned, there's plenty of complexity available should you want it. But, at its core, AppImages are actually quite straightforward. Rather than working through a repo like most other package managers, AppImages are single, standalone files that can be sent directly or shared through a website.

Here's an illustration of its beauty. While I was playing around with AppImages, I came across a very old discussion on a tech forum that led me to an equally old and abandoned GitHub project and associated YAML and recipe files. They were designed to automatically build the rather complex infrastructure required to prepare the archive needed to generate an AppImage package. Although that infrastructure was all built to run on a five-year-old release of Ubuntu, when I put it all together and ran the `appimagetool`

command against it, it created an AppImage file that worked seamlessly on my current desktop. I don't think there are too many five-year-old GitHub projects of that complexity that could run using other technologies without some serious reworking.

But I'm not going to go there. Instead, I'm going to show you how it works with a very simple Hello World application. First, make sure the AppStream package is installed locally.

For Debian-based system, run:

`$ sudo apt install appstream`


And for RPM systems, use:

`$ sudo dnf install appstream`


Clone the Git repo referenced in [this article](https://www.booleanworld.com/creating-linux-apps-run-anywhere-appimage/), which I based this example on:

```
$ git clone https://github.com/boolean-world/appimage-resources
$ cd appimage-resources
$ ls hello-world-appimage
```


Next, `cd`

into the new directory Git created, and take a look around. There are two directories here. Use `hello-world-appimage`

; the other one is a more complex project, and you should consider giving it a try, too.

The `helloworld.desktop`

file is what Linux GUI systems read to know how to handle the way they present a desktop icon. As it turns out, the way the file is currently written will give you trouble a bit later, so make one minor edit: add a `Categories=`

line and give it the value `GNOME`

. And don't forget the semicolon at the end:

```
$ nano hello-world-appimage/helloworld.desktop
add Categories=GNOME;
```


Download a precompiled copy of the `appimagetool`

binary from [the AppImage GitHub project](https://github.com/AppImage/AppImageKit/releases). Make a point of visiting the GitHub site—there's plenty of excellent documentation and resources there. Once the binary is downloaded, make the file executable and point it at the `hello-world-appimage`

directory. But first, you need to tell it what architecture you want. For some reason, a tool with a name that ends in `x86_64`

is all wobbly when it comes to choosing whether to build an application using x86_64 or not (I'm not sure what's going on there):

```
$ wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
$ chmod +x appimagetool-x86_64.AppImage
$ ARCH=x86_64 ./appimagetool-x86_64.AppImage hello-world-appimage
```


If you don't see any angry error messages, you're all set to give it a run:

```
$ ls
$ ./hello-world-appimage-x86_64.AppImage
```


## Conclusion

AppImage is an incredibly effective choice for package management. As you explore it, I think you'll find it's a great alternative to the defaults Linux distributions provide.

## 2 Comments