「PACKAGE-MANAGEMENT」- Flatpak

认识

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

Flatpak is a framework for distributing desktop applications across various Linux distributions. It was created by developers with a long history of working on the Linux desktop and is run as an independent open source project.

组成

Runtime

Basic concepts/Runtime

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

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

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

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

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 信息。

数据保存

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

Font and Fontconfig

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

Flatpak exposes fonts from the host to the sandbox, and the runtime ships the default fontconfig from upstream.

  • Fonts from /usr/share/fonts are exposed at /run/host/fonts,
  • from /usr/local/share/fonts at /run/host/local-fonts,
  • and from $XDG_DATA_HOME/fonts at /run/host/user-fonts.
  • ~/.fonts is a legacy path and should not be used.

Fontconfig config files from the host are not exposed.

https://github.com/flatpak/flatpak/issues/3947 如果需要使用 fonts.conf 配置,则需要通过额外的挂载来实现。

命令程序 and 配置文件

flatpak | https://docs.flatpak.org/en/latest/flatpak-command-reference.html#

flatpak-builder | https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html

性质

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.

提供桌面环境安全

https://docs.flatpak.org/en/latest/sandbox-permissions.html

功能:

  • One of Flatpak’s main goals is to increase the security of desktop systems by isolating applications from one another.

原理:

  • This is achieved using sandboxing and means that, by default, applications that are run with Flatpak have extremely limited access to the host environment.

提供应用安装功能(核心)

~/.local/share/flatpak/app ⇒ flatpak install –user … …

error: No remote refs found for ‘flathub’ | 如果使用 –user 选项来安装应用,则需要预先使用 –user 来添加仓库。

提供仓库管理功能

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

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

构造

版本选择

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

服务安装

Flatpak—the future of application distribution https://flatpak.org/setup/Ubuntu

apt install flatpak # Version: 1.16.0-2 Ubuntu 25.04 

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

应用

场景 | 用户 | 添加仓库,安装应用,应用升级,应用降级,应用卸载,……

How to Downgrade Flatpak Packages in Linux

# ----------------------------------------------------------------------------- # 仓库管理

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

flatpak remotes -d # 查看

# @date Sat Oct 25 12:16:21 PM CST 2025 修改 name 的方法 

# ----------------------------------------------------------------------------- # 安装应用

flatpak install flathub net.codeindustry.MasterPDFEditor # --user, --system (default)
flatpak run net.codeindustry.MasterPDFEditor

flatpak update
flatpak update flathub net.codeindustry.MasterPDFEditor

flatpak list --app
flatpak remote-info --log flathub <Application ID>
flatpak update --commit=<commit_code> <Application ID>
# 根据我们的观察,在 Ubuntu 20.04LTS 中,flatpak 会自动创建 .desktop 文件。

# System to User

flatpak list --app --system --columns=application | xargs -i flatpak install --assumeyes --user flathub {}

场景 | 开发 | 创建应用,构建应用,应用调试,……

Debugging – Flatpak documentation

# flatpak ps

# flatpak enter 1543828780 ls /run/host/

访问系统目录

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”

改进

[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

[DONE] … segfault … error 4 in libpangoft2-1.0.so … likely on CPU …

Ubuntu 25.04 Flatpak 1.16.0 Linux 6.14.0-32-generic 2025-10-15

针对该环境,多个 Flatpak 应用无法正常启动,已知有 Meld DingTalk Telegram Flatseal 应用 2025-10-15

根据文档及反馈,问题与字体相关。

针对我们的系统中,其有 2 个字体文件具有相同的 Font Family 及 Style 信息,我们猜测与该问题相关。所以,删除重复文件,问题得以解决。

参考

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