跳至内容

Flatpak

简介

来自项目的网页

Flatpak 是一个用于在各种 Linux 发行版之间分发桌面应用程序的框架。它由拥有悠久 Linux 桌面开发经验的开发者创建,并作为独立的开源项目运行。

在使用包含 GNOME 的软件选项(“带 GUI 的服务器”或“工作站”)安装 Rocky Linux 时,Flatpak 会默认安装。也可以手动安装。(参见包含的步骤) 它是为您的桌面环境填充您想使用的工具的绝佳方式。

手动安装

注意

如果您已经运行简介中描述的完整 GNOME 桌面环境,则可以跳过此步骤。

使用以下命令安装 Flatpak

sudo dnf install flatpak

添加 Flatpak 仓库

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

重启系统

sudo shutdown -r now

Flatpak 命令

要查看所有可用的 Flatpak 命令列表

flatpak --help

这将输出以下内容

Usage:
  flatpak [OPTION…] COMMAND

Builtin Commands:
 Manage installed applications and runtimes
  install                Install an application or runtime
  update                 Update an installed application or runtime
  uninstall              Uninstall an installed application or runtime
  mask                   Mask out updates and automatic installation
  pin                    Pin a runtime to prevent automatic removal
  list                   List installed apps and/or runtimes
  info                   Show info for installed app or runtime
  history                Show history
  config                 Configure flatpak
  repair                 Repair flatpak installation
  create-usb             Put applications or runtimes onto removable media

 Find applications and runtimes
  search                 Search for remote apps/runtimes

 Manage running applications
  run                    Run an application
  override               Override permissions for an application
  make-current           Specify default version to run
  enter                  Enter the namespace of a running application
  ps                     Enumerate running applications
  kill                   Stop a running application

 Manage file access
  documents              List exported files
  document-export        Grant an application access to a specific file
  document-unexport      Revoke access to a specific file
  document-info          Show information about a specific file

 Manage dynamic permissions
  permissions            List permissions
  permission-remove      Remove item from permission store
  permission-set         Set permissions
  permission-show        Show app permissions
  permission-reset       Reset app permissions

 Manage remote repositories
  remotes                List all configured remotes
  remote-add             Add a new remote repository (by URL)
  remote-modify          Modify properties of a configured remote
  remote-delete          Delete a configured remote
  remote-ls              List contents of a configured remote
  remote-info            Show information about a remote app or runtime

 Build applications
  build-init             Initialize a directory for building
  build                  Run a build command inside the build dir
  build-finish           Finish a build dir for export
  build-export           Export a build dir to a repository
  build-bundle           Create a bundle file from a ref in a local repository
  build-import-bundle    Import a bundle file
  build-sign             Sign an application or runtime
  build-update-repo      Update the summary file in a repository
  build-commit-from      Create new commit based on existing ref
  repo                   Show information about a repo

Help Options:
  -h, --help              Show help options

Application Options:
  --version               Print version information and exit
  --default-arch          Print default arch and exit
  --supported-arches      Print supported arches and exit
  --gl-drivers            Print active gl drivers and exit
  --installations         Print paths for system installations and exit
  --print-updated-env     Print the updated environment needed to run flatpaks
  --print-system-only     Only include the system installation with --print-updated-env
  -v, --verbose           Show debug information, -vv for more detail
  --ostree-verbose        Show OSTree debug information

记住命令列表是不必要的,但了解如何获取列表并使用 --help 选项是一个好主意。

警告

如果您使用的是 Rocky Linux 9.x 版本,则会遇到此错误。运行以下命令时

flatpak search [packagename]

其中 [packagename] 是您要查找的软件包,您将收到以下消息

F: Failed to parse /var/lib/flatpak/appstream/flathub/x86_64/active/appstream.xml.gz file: Error on line 4065 char 29: <p> already set '
  Organic Maps is a free Android & iOS offline maps app for travelers,
  tourists, hikers, drivers, and cyclists.
  It uses crowd-sourced OpenStreetMap data and is developed with love by
  ' and tried to replace with ' ('
No matches found

对此没有解决方法。要避免此错误,请使用本文档中的 Flathub 资源获取并安装所需的软件包。

Flathub

Flathub 是一个用于获取或提交桌面软件包的 Web 资源。

要浏览 Flathub,请访问 https://flathub.org/。这里有大量经过精心策划的桌面软件包,并按类别整齐地划分。

使用 Flathub 和 Flatpak

例如,OBS Studio 的安装过程如下所示

  1. 在 Flathub 上打开“音频和视频”部分

  2. 从列表中选择“OBS Studio”

  3. 单击“安装”按钮旁边的向下箭头

    flathub_install_1

    flathub_install_2

  4. 确保您已完成 Rocky Linux 的所有安装先决条件(第二张图片中的数字 1,上面已经完成),然后复制命令(第二张图片中的数字 2)并将其粘贴到终端中

    flatpak install flathub com.obsproject.Studio
    Looking for matches…
    Required runtime for com.obsproject.Studio/x86_64/stable (runtime/org.kde.Platform/x86_64/6.6) found in remote flathub
    Do you want to install it? [Y/n]: Y
    
  5. 当您回答“Y”并按下 Enter 时,您将看到以下内容

    com.obsproject.Studio permissions:
    ipc                             network         pulseaudio              wayland
    x11                             devices         file access [1]         dbus access [2]
    system dbus access [3]
    
    [1] host, xdg-config/kdeglobals:ro, xdg-run/pipewire-0
    [2] com.canonical.AppMenu.Registrar, org.a11y.Bus, org.freedesktop.Flatpak, org.freedesktop.Notifications,
        org.kde.KGlobalSettings, org.kde.StatusNotifierWatcher, org.kde.kconfig.notify
    [3] org.freedesktop.Avahi
    
        ID                                                    Branch         Op         Remote          Download
    1.     com.obsproject.Studio.Locale                          stable         i          flathub          < 47.0 kB (partial)
    2.     org.kde.KStyle.Adwaita                                6.6            i          flathub           < 8.0 MB
    3.     org.kde.Platform.Locale                               6.6            i          flathub         < 380.6 MB (partial)
    4.     org.kde.PlatformTheme.QGnomePlatform                  6.6            i          flathub           < 9.7 MB
    5.     org.kde.WaylandDecoration.QAdwaitaDecorations         6.6            i          flathub           < 1.2 MB
    6.     org.kde.Platform                                      6.6            i          flathub         < 325.0 MB
    7.     com.obsproject.Studio                                 stable         i          flathub         < 207.7 MB
    
    Proceed with these changes to the system installation? [Y/n]:
    
  6. 回答“Y”并按下 Enter 将更改系统权限(如上所示)并安装应用程序。

  7. 如果一切顺利,您应该收到以下信息

    Installation complete.
    
  8. 现在,您可以从“活动”菜单中搜索并运行 OBS Studio。

列出软件包

要查看系统上安装的 Flatpak,请打开终端并使用以下命令

flatpak list

这将显示以下输出

Name                                    Application ID                                  Version   Branch       Installation
OBS Project                             com.obsproject.Studio                           30.1.2    stable       system
FileZilla                               org.filezillaproject.Filezilla                  3.66.1    stable       system
Freedesktop Platform                    org.freedesktop.Platform                        22.08.24  22.08        system
Freedesktop Platform                    org.freedesktop.Platform                        23.08.16  23.08        system
Mesa                                    org.freedesktop.Platform.GL.default             24.0.4    22.08        system
Mesa (Extra)                            org.freedesktop.Platform.GL.default             24.0.4    22.08-extra  system
Mesa                                    org.freedesktop.Platform.GL.default             24.0.5    23.08        system
Mesa (Extra)                            org.freedesktop.Platform.GL.default             24.0.5    23.08-extra  system
Intel                                   org.freedesktop.Platform.VAAPI.Intel                      22.08        system
Intel                                   org.freedesktop.Platform.VAAPI.Intel                      23.08        system
openh264                                org.freedesktop.Platform.openh264               2.1.0     2.2.0        system
openh264                                org.freedesktop.Platform.openh264               2.4.1     2.4.1        system
The GIMP team                           org.gimp.GIMP                                   2.10.36   stable       system
GNOME Application Platform version 46   org.gnome.Platform                                        46           system
Adwaita theme                           org.kde.KStyle.Adwaita                                    6.6          system
KDE Application Platform                org.kde.Platform                                          6.6          system
QGnomePlatform                          org.kde.PlatformTheme.QGnomePlatform                      6.6          system
QAdwaitaDecorations                     org.kde.WaylandDecoration.QAdwaitaDecorations             6.6          system

更新软件包

要将软件包更新到最新版本,请使用 flatpak list 输出中的“应用程序 ID”

flatpak update com.obsproject.Studio

删除软件包

要卸载软件包,请使用 `flatpak list` 输出中的“应用程序 ID”。

flatpak uninstall com.obsproject.Studio

结论

您可以使用 Flathub 和 Flatpak 在您的 GNOME 桌面中轻松地添加应用程序,从游戏到生产力工具都有。

作者:史蒂文·斯宾塞

贡献者:甘娜·吉尔诺娃