> For the complete documentation index, see [llms.txt](https://handbook.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://handbook.bsdcn.org/di-4-zhang-an-zhuang-ying-yong-cheng-xu-ruan-jian-bao-he-ports/4.2.-ruan-jian-an-zhuang-de-gai-shu.md).

# 4.2.软件安装的概述

FreeBSD *port* 是一组用于自动化从源代码编译应用程序的文件。组成 port 的文件包含所有必要的信息，能够自动下载、解压、打补丁、编译和安装应用程序。

如果软件尚未适配并经过 FreeBSD 测试，可能需要编辑源代码，以便其能够正确安装和运行。

然而，已有超过 [36000](https://ports.freebsd.org/) 款第三方应用程序被移植到了 FreeBSD。当可行时，这些应用程序会作为预编译的 *软件包* 提供下载。

可以使用 FreeBSD 软件包管理命令来操作软件包。

软件包和 ports 都能处理依赖关系。如果使用软件包或 port 安装应用程序，而所依赖的库尚未安装，库将自动先行安装。

FreeBSD 软件包包含应用程序所有命令的预编译副本，以及任何配置文件和文档。可以使用 [pkg(8)](https://man.freebsd.org/cgi/man.cgi?query=pkg\&sektion=8\&format=html) 命令（例如 `pkg install`）来操作软件包。

尽管这两种技术相似，软件包和 ports 各有优势。选择满足安装特定应用程序需求的技术。

**软件包的优点**

* 压缩的软件包 tarball 通常比包含应用程序源代码的压缩包小。
* 软件包不需要编译时间。对于大型应用程序，如 Firefox、KDE Plasma 或 GNOME，这在系统较慢时尤为重要。
* 软件包不需要了解在 FreeBSD 上编译软件的过程。

**Ports 的优点**

* 软件包通常使用保守选项进行编译，因为它们必须在最大数量的系统上运行。通过从 port 编译，可以更改编译选项。
* 一些应用程序有与安装哪些功能相关的编译时选项。例如，NGINX® 可以通过各种内建选项进行配置。 在某些情况下，同一个应用程序可能会有多个软件包，具有不同的设置。例如，NGINX® 有 `nginx` 软件包和 `nginx-lite` 软件包，前者启用了更多的选项，但这也需要安装更多的依赖项，因此会增加空间消耗和攻击面。

  传递依赖可能会变得相当庞大，例如完整的 `nginx` 软件包会拉入多个 X 库，这可能让人感到惊讶，因此从 port 编译可以让你选择仅需要的选项，而不使用“大杂烩”方式。在某些情况下，可能会为同一应用程序提供多个软件包，以指定特定设置。
* 某些软件的许可条款禁止二进制分发。这类软件必须以源代码形式分发，且必须由最终用户编译。
* 有些人不信任二进制分发，或更愿意通过源代码查找潜在问题。
* 应用自定义补丁时需要源代码。

要跟踪更新的 ports，可以订阅 [FreeBSD ports 邮件列表](https://lists.freebsd.org/subscription/freebsd-ports) 和 [FreeBSD ports bugs 邮件列表](https://lists.freebsd.org/subscription/freebsd-ports-bugs)。

> **警告**
>
> 在安装应用程序之前，请检查 <https://vuxml.freebsd.org/> 以了解相关的安全问题。
>
> 要审计已安装的软件包以检查已知漏洞，请运行 `pkg audit -F`。

本章的其余部分将说明如何使用软件包和 ports 在 FreeBSD 上安装和管理第三方软件。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://handbook.bsdcn.org/di-4-zhang-an-zhuang-ying-yong-cheng-xu-ruan-jian-bao-he-ports/4.2.-ruan-jian-an-zhuang-de-gai-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
