本页内容

  • 先决条件
  • 安装 Flatpak
  • 启用 Flatpak 软件仓库
  • 使用 Flatpak 搜索应用程序
  • 使用 Flatpak 安装 Google Chrome
  • 运行 Flatpak 应用程序
  • 使用 Flatpak 卸载应用程序
  • 总结

Flatpak(原名 xdg-app)是 Linux 操作系统的一款包管理工具,可让你通过 flatpak 包管理器安装和管理软件包。Flatpak 拥有自己的软件仓库,因此你无需依赖其他仓库,它会提供软件安装所需的全部库文件与依赖项。它是一套跨发行版的应用部署框架,开发者可以针对所有主流发行版为应用程序配置 Flatpak 打包。

本文演示如何在 Ubuntu 22.04 上安装并使用 Flatpak 包管理工具。

先决条件

  • 一台运行 Ubuntu 22.04 的服务器。
  • 服务器上已配置 root 密码。

安装 Flatpak

默认情况下,Flatpak 软件包已包含在 Ubuntu 的默认仓库中,你可以运行以下命令进行安装:

apt install flatpak -y

你应该会看到如下输出:

flatpak --version

在使用 Flatpak 之前,你需要先将 Flatpak 仓库添加到系统中,可通过以下命令添加:

Flatpak 1.12.7

使用 Flatpak 搜索应用程序

Flatpak 提供搜索功能,可通过命令行界面搜索可用的应用程序。

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

例如,要搜索 Telegram 应用,请运行以下命令:

你应该会得到如下结果:

要搜索 Skype,请运行以下命令:

你应该会看到如下输出:

flatpak search application-name

首先,使用以下命令搜索 Google Chrome 应用:

flatpak search telegram

现在,你可以使用上面输出中的应用程序 ID 来安装 Google Chrome:

Name                    Description                                                           Application ID            Version Branch Remotes
Telegram Desktop        Fast. Secure. Powerful.                                               org.telegram.desktop      4.3.1   stable flathub
Telegram Desktop Webvi… Webview add-on that enables Telegram Desktop to show web content      …telegram.desktop.webview 2.38.2  stable flathub
Kotatogram Desktop      Kotatogram Desktop messenger                                          io.github.kotatogram      1.4.8   stable flathub
LibreTrack              Private, cross-platform package tracking app                          …roninyaroslav.libretrack 1.3.0   stable flathub
Tangram                 Browser for your pinned tabs                                          re.sonny.Tangram          1.4.2   stable flathub
Bolls                   A web app for reading the Bible with full emphasis on the God`s Word… life.bolls.bolls          2.1.80  stable flathub
Franz                   Messenger for the desktop                                             com.meetfranz.Franz       5.9.1   stable flathub
Delta Chat              Delta Chat email-based messenger                                      chat.delta.desktop        v1.32.1 stable flathub

要列出所有已安装的应用程序,请运行以下命令:

flatpak search skype

运行 Flatpak 应用程序

Name         Description                                                 Application ID            Version          Branch       Remotes
Skype        Call and message skype users, with video chat support       com.skype.Client          8.90.0.407       stable       flathub
Franz        Messenger for the desktop                                   com.meetfranz.Franz       5.9.1            stable       flathub

上述命令将启动 Google Chrome 的图形界面应用程序。

使用 Flatpak 卸载应用程序

flatpak search chrome

你应该会看到如下输出:

Name              Description                                                       Application ID             Version          Branch Remotes
Google Chrome     The web browser from Google                                       com.google.Chrome          107.0.5304.110-1 stable flathub
Chromium Web Bro… The web browser from Chromium project                             org.chromium.Chromium      107.0.5304.110   stable flathub
ungoogled-chromi… A lightweight approach to removing Google web service dependency  …Eloston.UngoogledChromium 107.0.5304.110   stable flathub
Google Chrome (u… The web browser from Google                                       com.google.ChromeDev       109.0.5410.0-1   stable flathub
CrosAdapta        Chrome OS GTK theme                                               ….gtk.Gtk3theme.CrosAdapta                  3.22   flathub
PhotoQt Image Vi… View and manage images                                            org.photoqt.PhotoQt        2.9.1            stable flathub
Firestorm Viewer  Client for accessing 3D virtual worlds                            …ormviewer.FirestormViewer 6.3.9.58205      stable flathub
Joplin            A free, open source note taking and to-do application, which can… net.cozic.joplin_desktop   2.8.8            stable flathub
Google Play Musi… Run Google Play Music as a standalone desktop app                 …ymusicdesktopplayer.GPMDP 4.7.1            stable flathub
Gabut Download M… Simple and Faster Download Manager                                ….github.gabutakut.gabutdm 1.9.9            stable flathub
Postman           Postman is a complete API development environment.                com.getpostman.Postman     10.1.2           stable flathub
Boxy SVG          Scalable Vector Graphics editor                                   com.boxy_svg.BoxySVG       3.92.0           stable flathub

要获取更多关于 Flatpak 命令的信息,请运行以下命令:

flatpak install com.google.Chrome

总结

Looking for matches…
Required runtime for com.google.Chrome/x86_64/stable (runtime/org.freedesktop.Platform/x86_64/22.08) found in remote flathub
Do you want to install it? [Y/n]: Y

com.google.Chrome permissions:
    ipc                        network                         cups             pcsc                    pulseaudio
    wayland                    x11                             devices          file access [1]         dbus access [2]
    bus ownership [3]          system dbus access [4]          tags [5]

    [1] /run/.heim_org.h5l.kcm-socket, host-etc, xdg-documents, xdg-download, xdg-music, xdg-pictures, xdg-run/dconf, xdg-run/pipewire-0,
        xdg-videos, ~/.config/dconf:ro, ~/.config/kioslaverc
    [2] ca.desrt.dconf, org.freedesktop.FileManager1, org.freedesktop.Notifications, org.freedesktop.secrets, org.gnome.SessionManager
    [3] org.mpris.MediaPlayer2.chromium.*
    [4] org.freedesktop.Avahi, org.freedesktop.UPower
    [5] proprietary


        ID                                             Branch            Op           Remote            Download
 1.     org.freedesktop.Platform.GL.default            22.08             i            flathub           < 131.0 MB
 2.     org.freedesktop.Platform.Locale                22.08             i            flathub           < 333.0 MB (partial)
 3.     org.freedesktop.Platform.openh264              2.2.0             i            flathub           < 944.3 kB
 4.     org.freedesktop.Platform                       22.08             i            flathub           < 214.4 MB
 5.     com.google.Chrome                              stable            i            flathub           < 100.1 MB

Proceed with these changes to the system installation? [Y/n]: Y

要列出所有已安装的应用,请运行以下命令:

flatpak list

您将看到如下列表:

Name                           Application ID                                Version                   Branch          Installation
Google Chrome                  com.google.Chrome                             107.0.5304.110-1          stable          system
Freedesktop Platform           org.freedesktop.Platform                      22.08.3                   22.08           system
Mesa                           org.freedesktop.Platform.GL.default           22.1.7                    22.08           system
openh264                       org.freedesktop.Platform.openh264             2.1.0                     2.2.0           system

运行 Flatpak 应用

安装 Google Chrome 应用后,可通过运行以下命令启动它:

flatpak run com.google.Chrome

上述命令将启动 Google Chrome 图形界面应用。

使用 Flatpak 移除应用

要移除 Google Chrome 应用,请运行以下命令:

flatpak uninstall com.google.Chrome

您应该会看到如下输出:

        ID                      Branch       Op
 1.     com.google.Chrome       stable       r

Proceed with these changes to the system installation? [Y/n]: Y

要移除未使用的应用,请运行以下命令:

flatpak uninstall --unused

要获取有关 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

总结

恭喜!您已成功在 Ubuntu 22.04 上安装 Flatpak。现在您可以将 Flatpak 作为 APT 的替代包管理器来安装和管理软件包。如果您有任何问题,欢迎随时向我提问。