在 Ubuntu 上安装和使用 Flatpak
Flatpak
![](/data/attachment/album/202307/24/230017g1qhhwfzhhhcyz13.jpg)



> 
> Ubuntu 可能默认安装了 Snap，但你仍然可以使用 Flatpak 通用软件包。
> 
> 
> 


Linux 世界有三种“通用”打包格式，允许在“任何” Linux 发行版上运行：Snap、Flatpak 和 AppImage。


Ubuntu 内置了 Snap，但大多数发行版和开发人员都避免使用它，因为它的闭源性质。他们更喜欢 [Fedora 的 Flatpak 打包系统](https://itsfoss.com/what-is-flatpak/)。


作为 Ubuntu 用户，你并不局限于 Snap。你还可以在 Ubuntu 系统上使用 Flatpak。


在本教程中，我将讨论以下内容：


* 在 Ubuntu 上启用 Flatpak 支持
* 使用 Flatpak 命令来管理包
* 从 Flathub 获取包
* 将 Flatpak 软件包添加到软件中心


听起来很令人兴奋？ 让我们一一看看。


### 在 Ubuntu 上安装 Flatpak


你可以使用以下命令轻松安装 Flatpak：



```
sudo apt install flatpak

```

对于 **Ubuntu 18.04 或更早版本**，请使用 PPA：



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

```

#### 添加 Flathub 仓库


你已在 Ubuntu 系统中安装了 Flatpak 支持。但是，如果你尝试安装 Flatpak 软件包，你将收到 [“No remote refs found”](https://itsfoss.com/no-remote-ref-found-flatpak/) 错误。这是因为没有添加 Flatpak 仓库，因此 Flatpak 甚至不知道应该从哪里获取应用。


Flatpak 有一个名为 “Flathub” 的集中仓库，可以从此处找到并下载许多 Flatpak 应用。


你应该添加 Flathub 仓库来访问这些应用。



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

```

![Install Flatpak in latest versions of Ubuntu and then add Flathub repo](/data/attachment/album/202307/24/230051f1l2wqiwlcxpyivw.svg)


安装并配置 Flatpak 后，**重启你的系统**。否则，已安装的 Flatpak 应用将不会在你的系统菜单上可见。


不过，你始终可以通过运行以下命令来运行 Flatpak 应用：



```
flatpak run <package-name>

```

### 常用 Flatpak 命令


现在你已经安装了 Flatpak 打包支持，是时候学习包管理所需的一些最常见的 Flatpak 命令了。


#### 搜索包


如果你知道应用名称，请使用 Flathub 网站或使用以下命令：



```
flatpak search <package-name>

```

![Search for a package using Flatpak Search command](/data/attachment/album/202307/24/230051kcig3cgzrmio87zr.svg)



> 
> ? 除了搜索 Flatpak 包之外，在其他情况下， 指的是正确的 Flatpak 包名称，例如 `com.raggesilver.BlackBox`（上面截图中的应用 ID）。你还可以使用应用 ID 的最后一个词 `Blackbox`。
> 
> 
> 


#### 安装 Flatpak 包


以下是安装 Flatpak 包的语法：



```
flatpak install <remote-repo> <package-name>

```

由于几乎所有时候你都会从 Flathub 获取应用，因此远程仓库将是 `flathub`：



```
flatpak install flathub <package-name>

```

![Install a package after searching for its name](/data/attachment/album/202307/24/230051fhqi8sggp4tgsing.svg)


在极少数情况下，你可以直接从开发人员的仓库安装 Flatpak 包，而不是 Flathub。在这种情况下，你可以使用如下语法：



```
flatpak install --from https://flathub.org/repo/appstream/com.spotify.Client.flatpakref

```

#### 从 flatpakref 安装包


这是可选的，也很少见。但有时，你会获得应用的 `.flatpakref` 文件。这**不是离线安装**。.flatpakref 包含有关从何处获取包的必要详细信息。


要从此类文件安装，请打开终端并运行：



```
flatpak install <path-to-flatpakref file>

```

![Install a Flatpak package from Flatpakref file](/data/attachment/album/202307/24/230052um1hkeotfzcxx10x.svg)


#### 从终端运行 Flatpak 应用


再说一遍，这是你不会经常做的事情。大多数情况下，你将在系统菜单中搜索安装应用并从那里运行该应用。


但是，你也可以使用以下命令从终端运行它们：



```
flatpak run <package-name>

```

#### 列出已安装的 Flatpak 软件包


想要查看你的系统上安装了哪些 Flatpak 应用？ 像这样列出它们：



```
flatpak list

```

![List all the installed Flatpak packages on your system](/data/attachment/album/202307/24/230052lfssbnuia7dxxmxj.svg)


#### 卸载 Flatpak 包


你可以通过以下方式删除已安装的 Flatpak 包：



```
flatpak uninstall <package-name>

```

如果你想**清除不再需要的剩余包和运行时**，请使用：



```
flatpak uninstall --unused

```

![Remove a Flatpak package and later, if there is any unused runtimes or packages, remove them](/data/attachment/album/202307/24/230052obp5gbxy33pzhph7.svg)


它可能会帮助你 [在 Ubuntu 上节省一些磁盘空间](https://itsfoss.com/free-up-space-ubuntu-linux/)。


### Flatpak 命令总结


以下是你在上面学到的命令的快速摘要：




| 用途 | 命令 |
| --- | --- |
| 搜索包 | `flatpak search` |
| 安装包 | `flatpak install` |
| 列出已安装的包 | `flatpak list` |
| 从 flatpakref 安装 | `flatpak install <package-name.flatpakref>` |
| 卸载软件包 | `flatpak uninstall` |
| 卸载未使用的运行时和包 | `flatpak uninstall --unused` |


### 使用 Flathub 探索 Flatpak 包


我知道通过命令行搜索 Flatpak 包并不是最好的体验，这就是 [Flathub 网站](https://flathub.org:443/en-GB) 的用武之地。


你可以在 Flathub 上浏览 Flatpak 应用，它提供了更多详细信息，例如经过验证的发布商、下载总数等。


你还将在应用页面底部获得安装应用所需的命令。


![](/data/attachment/album/202307/24/230052e8mfr77mfpkonmqn.png)


![](/data/attachment/album/202307/24/230053yqkbxk1zf0v8bv87.png)


### 额外信息：使用支持 Flatpak 软件包的软件中心


你可以将 Flatpak 包添加到 GNOME 软件中心，并使用它以图形方式安装软件包。


有一个专用插件可以将 Flatpak 添加到 GNOME 软件中心。



> 
> ? 从 Ubuntu 20.04 开始，Ubuntu 默认的软件中心是 Snap Store，并且不支持 Flatpak 集成。因此，安装以下软件包将产生两个软件中心：一个 Snap 和另一个 DEB。
> 
> 
> 


![When you install GNOME Software Flatpak plugin in Ubuntu, a DEB version of GNOME Software is installed. So you will have two software center application](/data/attachment/album/202307/24/230053bm51mdp57m2x6wup.png)



```
sudo apt install gnome-software-plugin-flatpak

```

![Installing GNOME Software Plugin in Ubuntu](/data/attachment/album/202307/24/230054zfkgooqclhyfptrp.svg)


### 总结


你在这里学到了很多东西。你学习了在 Ubuntu 中启用 Flatpak 支持并通过命令行管理 Flatpak 软件包。你还了解了与软件中心的集成。


我希望你现在对 Flatpaks 感觉更舒服一些。既然你发现了三个通用软件包之一，那么再 [了解一下 Appimages](https://itsfoss.com/use-appimage-linux/) 怎么样？


如果你有疑问或遇到任何问题，请告诉我。


*（题图：MJ/d03886af-9b7f-401e-a964-da0e5d6531a2）*




---


via: <https://itsfoss.com/flatpak-ubuntu/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


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


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

The Linux world has three 'universal' packaging formats that allow running on 'any' Linux distribution; Snap, Flatpak and AppImage.

Ubuntu comes baked-in with Snap but most distributions and developers avoid it because of its close source nature. They prefer [Fedora's Flatpak packaging system](https://itsfoss.com/what-is-flatpak/).

As an Ubuntu user, you are not restricted to Snap. You also can use Flatpak on your Ubuntu system.

In this tutorial, I'll discuss the following:

- Enabling Flatpak support on Ubuntu
- Using Flatpak commands to manage packages
- Getting packages from Flathub
- Add Flatpak packages to Software Center

Sounds exciting? Let's see them one by one.

## Installing Flatpak on Ubuntu

You can easily install Flatpak using the following command:

`sudo apt install flatpak`


For ** Ubuntu 18.04 or older versions**, use PPA:

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


### Add Flathub repo

You have installed Flatpak support in your Ubuntu system. However, if you try to install a Flatpak package, you'll get '[No remote refs found' error](https://itsfoss.com/no-remote-ref-found-flatpak/). That's because there are no Flatpak repositories added and hence Flatpak doesn't even know from where it should get the applications.

Flatpak has a centralized repository called Flathub. A number of Flatpak applications can be found and downloaded from here.

You should add the Flathub repo to access those applications.

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


Once Flatpak is installed and configured, **restart your system**. Otherwise, installed Flatpak apps won't be visible on your system menu.

Still, you can always run a flatpak app by running:

`flatpak run <package-name>`


## Common Flatpak Commands

Now that you have Flatpak packaging support installed, it's time to learn some of the most common Flatpak commands needed for package management.

### Search for a Package

Either use Flathub website or use the following command, if you know the application name:

`flatpak search <package-name>`


Except for searching a flatpak package, on other instances, the <package-name> refers to the proper Flatpak package name, like `com.raggesilver.BlackBox`

(Application ID in the above screenshot). You may also use the last word `Blackbox`

of the Application ID.

### Install a Flatpak package

Here's the syntax for installing a Flatpak package:

`flatpak install <remote-repo> <package-name>`


Since almost all the times you'll be getting applications from Flathub, the remote repository will be `flathub`

:

`flatpak install flathub <package-name>`


In some rare cases, you may install Flatpak packages from the developer's repository directly instead of Flathub. In that case, you use a syntax like this:

`flatpak install --from https://flathub.org/repo/appstream/com.spotify.Client.flatpakref`


### Install a package from flatpakref

This is optional and rare too. But sometime, you will get a `.flatpakref`

file for an application. This is **NOT an offline installation**. The .flatpakref has the necessary details about where to get the packages.

To install from such a file, open a terminal and run:

`flatpak install <path-to-flatpakref file>`


### Run a Flatpak application from the terminal

Again, something you won't be doing it often. Mostly, you'll search for the installing application in the system menu and run the application from there.

However, you can also run them from the terminal using:

`flatpak run <package-name>`


### List installed Flatpak packages

Want to see which Flatpak applications are installed on your system? List them like this:

`flatpak list`


### Uninstall a Flatpak package

You can remove an installed Flatpak package in the following manner:

`flatpak uninstall <package-name>`


If you want to **clear the leftover packages and runtimes, that are no longer needed**, use:

`flatpak uninstall --unused`


It may help you [save some disk space on Ubuntu](https://itsfoss.com/free-up-space-ubuntu-linux/).

## Flatpak commands summary

Here's a quick summary of the commands you learned above:

Usage | Command |
---|---|

Search for Packages | flatpak search |

Install a Package | flatpak install |

List Installed Package | flatpak list |

Install from flatpakref | flatpak install <package-name.flatpakref> |

Uninstall a Package | flatpak uninstall |

Uninstall Unused runtimes and packages | flatpak uninstall --unused |


## Using Flathub to explore Flatpak packages

I understand that searching for Flatpak packages through the command line is not the best experience and that's where the [Flathub website](https://flathub.org/en-GB) comes into picture.

You can browse the Flatpak application on Flathub, which provides additional details like verified publishers, total number of downloads etc.

You'll also get the commands you need to use for installing the applications at the bottom of the application page.

![](https://itsfoss.com/content/images/2023/06/Flathub-apps-page-2.png)

![](https://itsfoss.com/content/images/2023/06/application-details-in-flathub-website-2.png)

Application Details in Flathub Official Website

## Bonus: Use Software Center with Flatpak package support

You can add the Flatpak packages to the GNOME Software Center application and use it for installing packages graphically.

There is a dedicated plugin to add Flatpak to GNOME Software Center.

Since Ubuntu 20.04, the default software center in Ubuntu is Snap Store and it does not support flatpak integration. So, installing the below package will result in two software centers simultaneously: one Snap and another DEB.

![When you install GNOME Software Flatpak plugin in Ubuntu, a DEB version of GNOME Software is installed. So you will have two software center application](https://itsfoss.com/content/images/2023/06/two-software-centers-in-Ubuntu.png)

`sudo apt install gnome-software-plugin-flatpak`


## Conclusion

You learned plenty of things here. You learned to enable Flatpak support in Ubuntu and manage Flatpak packages through the command line. You also learned about the integration with the Software Center.

I hope you feel a bit more comfortable with Flatpaks now. Since you discovered one of the three universal packages, how about [learning about Appimages](https://itsfoss.com/use-appimage-linux/)?

[How to Use AppImage in Linux [Complete Guide]What is AppImage? How to run it? How does it work? Here’s the complete guide about using AppImage in Linux.](https://itsfoss.com/use-appimage-linux/)![](https://itsfoss.com/content/images/wordpress/2017/07/use-appimage-linux.png)


![](https://itsfoss.com/content/images/wordpress/2017/07/use-appimage-linux.png)

*Let me know if you have questions or if you face any issues.*