「PACKAGE-MANAGEMENT」- Flatpak

认识

官网:https://flathub.org/en
文档:https://docs.flatpak.org/en/latest/
仓库:https://github.com/flatpak/flatpak

组成

Runtime

Basic concepts/Runtime

Runtime 提供应用程序使用的基本依赖项。每个应用程序都必须针对 Runtime 构建,并且该 Runtime 必须安装在主机系统上才能运行应用程序(Flatpak 可以自动安装应用程序所需的 Runtime)。可以同时安装多个不同的 Runtime,包括同一 Runtime 的不同版本。

Runtime 与发行版无关,并且不依赖于特定的发行版版本。这意味着它们为应用程序提供了稳定的跨发行版基础,并允许应用程序继续工作,而不受操作系统更新的影响。

简单解释,应用运行还是需要桌面环境(例如 GNOME KDE 等等)提供的函数库,而 Flakpak 在计算机上统一安装并管理这些函数库,并称之为 Runtime(运行时)。

现在(07/18/2024),官方提供 Freedesktop、GNOME、KDE、elementary 这些 Runtime 环境。| Available Runtimes

Flathub | Apps for Linux

官方:https://flathub.org/en

自建:https://github.com/flatpak/flat-manager
https://docs.flatpak.org/en/latest/hosting-a-repository.html

数据保存

Q:用户数据及应用数据的保存目录?
A:XDG_XXX_HOME ~/.var/
R:Requirements & Conventions – Flatpak documentation

Q:其在哪里保存的 .desktop 文件?
A:/var/lib/flatpak/exports/share/applications/
R:Where are all the installed flatpak apps .desktop files located · Issue #1286 · flatpak/flatpak

构造

版本选择

Releases | https://github.com/flatpak/flatpak/releases

安装

Flatpak—the future of application distribution

apt install flatpak

sudo add-apt-repository ppa:flatpak/stable
sudo apt update
sudo apt install flatpak

apt install gnome-software-plugin-flatpak

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

reboot

性质

Build for every distro
Create one app and distribute it to the entire Linux desktop market.

Stable platforms
Runtimes provide platforms of common libraries that you can depend on.

Consistent environments
Develop and test your application in an environment that’s identical to the one users have.

Full control over dependencies
Flatpak makes it easy to bundle your own libraries as part of your app.

Easy build tools
Flatpak’s build tools are simple and easy to use, and come with a full set of documentation.

Future-proof builds
Flatpak apps continue to be compatible with new versions of Linux distributions.

Distribution made easy
Make your app available to a rapidly growing audience of Flatpak users, with Flathub.

An independent project
Flatpak is developed by an independent community, with no lock-in to a single vendor.

应用

使用

flatpak install flathub net.codeindustry.MasterPDFEditor
flatpak run net.codeindustry.MasterPDFEditor

根据我们的观察,在 Ubuntu 20.04LTS 中,flatpak 会自动创建 .desktop 文件。

软件降级

How to Downgrade Flatpak Packages in Linux

flatpak list –app
flatpak remote-info –log flathub <Application ID>
flatpak update –commit=<commit_code> <Application ID>

配置权限

Flatseal
https://flathub.org/apps/com.github.tchx84.Flatseal
flatpak install flathub com.github.tchx84.Flatseal
flatpak run com.github.tchx84.Flatseal

配置环境变量:在 Flatseal 中,选中应用,Environment,为应用添加环境变量,重启应用即可。

访问系统目录

Give Flatpak application access to /usr/bin, /etc/ and /var directories of the host system?

通过 Flatseal 工具,授权应用访问系统目录。
默认挂载于 /run/host/ 目录

flatpak mounts the system under “/var/run/host”

应用调试 | Debuggging

Debugging – Flatpak documentation

# flatpak ps

# flatpak enter 1543828780 ls /run/host/

Runtime

software updates – How to list all flatpak apps that use a specific runtime?

flatpak list –runtime # 查看所有 Runtime
flatpak uninstall –unused # 删除未使用的 Runtime
flatpak list –app –app-runtime org.gnome.Platform//3.30 # 查看使用特定 Runtime 的应用。
flatpak info –show-runtime <appid> # 查看 App 所有的 Runtime 信息。

Fontconfig

https://www.reddit.com/r/flatpak/comments/spwck9/flatpak_doesnt_follow_custom_fontconfig_file/
https://github.com/flatpak/flatpak/issues/2861

改进

[WIP] 实现应用自动更新

现在 05/12/2025 Flatpak 1.14.10 暂时不支持自动更新应用,需要我们通过脚本自己来实现。

[WIP] … Error 71 (Protocol error) dispatching to Wayland display …

# flatpak run com.github.tchx84.Flatseal
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:763: FINISHME: support YUV colorspace with DRM format modifiers
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:794: FINISHME: support more multi-planar formats with DRM modifiers
Gdk-Message: 01:21:01.419: Error 71 (Protocol error) dispatching to Wayland display.

Gdk-Message: Error 71 (Protocol error) dispatching to Wayland display – Fedora Discussion

[WIP] … Very long start from shortcut/desktop icon on Flatpak, Ubuntu 24.10 #5968 …

https://github.com/flatpak/flatpak/issues/5968

通过 Flatpak 安装并运行的 Chrome Firefox Edge 都存在该问题,通过 .desktop 启动需要等待较长时间。但是,其他应用我们暂时未发现该问题。

尝试如下方法:

  • Selecting ‘Include apps from all workspaces’ instead of ‘Include apps from the current workspace only’ under ‘Multitasking’ in gnome-control-center solved this issue for me.

WIP

参考

Flatpak—the future of application distribution
Introduction to Flatpak – Flatpak documentation