# Chocolatey

**Chocolatey** 是 Windows 上的一款机器级包管理器，构建于 NuGet 打包框架与 [PowerShell](https://www.edgepedia.org/zh/powershell) 之上，用于安装、升级和卸载软件，其方式通常是封装现有的 Windows 安装程序（MSI、EXE 及类似格式），而非取而代之<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup>。Chocolatey 由一个命令行客户端和 Chocolatey 社区仓库（Chocolatey Community Repository）组成，后者是一个基于 NuGet 的公共包源，客户端可指向该源<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。厂商另售商业版本 Chocolatey for Business（C4B），按节点（机器）授权<sup>[3](https://chocolatey.org/pricing)</sup>。

| 关键事实 | 详情 |
|---|---|
| 是什么 | 基于 NuGet 和 PowerShell 构建的 Windows 包管理器，通常封装现有的 MSI 和 EXE 安装程序<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup> |
| 社区仓库 | 创建于 2011 年 9 月 1 日；2025 年 8 月 27 日达到 40 亿次安装，拥有 10,905 个唯一包，包版本总数为 264,188 个<sup>[4](https://blog.chocolatey.org/2025/08/four-billion-installs/)</sup> |
| 包格式 | 一个重命名为 .nupkg 的 zip 压缩包，内含 nuspec 元数据文件以及 chocolateyInstall.ps1 等 PowerShell 脚本<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup><sup> • </sup><sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup> |
| 审核 | 自 2014 年 10 月起提交的每个包版本都须经过审核，包括 VirusTotal 扫描和沙箱环境下的安装/卸载测试，通过后才会上线<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup><sup> • </sup><sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup> |
| 免费与付费 | Chocolatey for Business 起价为每年 1,800 美元（最低 100 节点，每节点每年 18.00 美元）<sup>[3](https://chocolatey.org/pricing)</sup> |
| 企业立场 | Chocolatey Software 不建议将社区仓库用于组织部署，而是推荐使用内部自托管仓库<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup> |
| 集成 | Ansible、Chef、Puppet、PowerShell DSC、Salt 等工具对 Chocolatey 有专门支持<sup>[6](https://chocolatey.org/how-chocolatey-works)</sup> |

## 工作原理

Chocolatey 包是一个重命名为 .nupkg 扩展名的 zip 文件，遵循微软创建的 NuGet 打包方式。包内携带 XML 元数据（nuspec 清单），客户端用它来识别包、版本及依赖关系，此外还包含 PowerShell 脚本，用于从 URL 下载安装程序或将安装程序嵌入包内<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup>。社区包是 zip 压缩包，内含软件文件或安装程序以及 chocolateyInstall.ps1 等 PowerShell 指令<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。大多数使用 PowerShell 的包会下载应用程序安装程序并以静默方式执行<sup>[7](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)</sup>。

**安装生命周期。** 安装包时，Chocolatey 使用 NuGet（NuGet.Core.dll）从源中检索包，源可以是文件夹、文件共享，或通过 HTTP 或 HTTPS 访问的 OData 位置<sup>[7](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)</sup>。包被安装到 `$env:ChocolateyInstall\lib\`，该位置刻意不可配置，因为跟踪、升级和卸载都依赖于包存放于此<sup>[7](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)</sup>。随后 Chocolatey 对注册表做快照以供后续比对，运行包中的 PowerShell 自动化脚本（如有），将卸载信息保存到 .registry 文件，并在 `$env:ChocolateyInstall\bin` 中为可执行文件生成代理程序（shim）<sup>[7](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)</sup>。底层的 MSI 和 EXE 安装程序仍通过其常规安装方式运行；Chocolatey 充当它们的封装层<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup>。

**升级与回滚。** 升级过程中，Chocolatey 从现有包中运行 chocolateyBeforeModify.ps1，备份包文件夹，若升级失败，则自动将包文件夹回滚至先前版本，同时传递错误信息<sup>[7](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)</sup>。版本管理和依赖处理是客户端的核心行为之一<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)</sup>。

## 历史与增长

Chocolatey 社区仓库创建于 2011 年 9 月 1 日，当时有 51 个唯一包，包总数为 161 个<sup>[4](https://blog.chocolatey.org/2025/08/four-billion-installs/)</sup>。安装量增长不断加速：第一个 10 亿次安装耗时 8.7 年（于 2020 年 5 月 19 日达到），而第四个 10 亿次仅用了 1.2 年<sup>[4](https://blog.chocolatey.org/2025/08/four-billion-installs/)</sup>。30 亿次里程碑落在 2024 年 5 月 31 日，当时仓库拥有略低于 10,500 个唯一包，包总数略高于 220,000 个<sup>[4](https://blog.chocolatey.org/2025/08/four-billion-installs/)</sup>。

## 版本与授权

Chocolatey for Business 按节点（机器）授权，计入物理、虚拟、容器、本地、云端和测试环境<sup>[3](https://chocolatey.org/pricing)</sup>。含标准支持的年度定价起价为每年 1,800 美元，即最低 100 节点、每节点每年 18.00 美元，节点数达到 500 起有阶梯折扣，10,000 节点及以上降至每节点 16.50 美元<sup>[3](https://chocolatey.org/pricing)</sup>。含标准支持的永久授权价格为 40 至 499 节点每节点 54.00 美元，10,000 节点及以上每节点 49.51 美元<sup>[3](https://chocolatey.org/pricing)</sup>。

授权版本增加了面向组织的功能。包内部化工具（Package Internalizer）可将 7,000 多个社区包内部化，供环境内部使用<sup>[6](https://chocolatey.org/how-chocolatey-works)</sup>。授权版本还执行运行时病毒扫描验证，Chocolatey CDN 为授权用户缓存已下载的资源，目前能缓存约 70% 的现有包<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。

## 社区仓库与审核

2024 年 3 月，Chocolatey 社区仓库被描述为 NuGet v2 端点，并计划迁移至 NuGet v3<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。仓库首页列出了 11,935 个由社区维护的稳定包<sup>[8](https://community.chocolatey.org/packages/)</sup>。

**审核流水线。** 自 2014 年 10 月起提交的每个包及每个包版本在上线前都要经过审核流程<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。该流水线包括包验证器（Package Validator）、包核验器（Package Verifier，在 [Windows Server 2019](https://www.edgepedia.org/zh/windows-server-2019) 沙箱中安装和卸载包）以及包扫描器（Package Scanner，收集包安装的文件并提交至 [VirusTotal](https://www.edgepedia.org/zh/virustotal)，后者使用 70 多种杀毒引擎检查项目）<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。人工审核员审查提交内容，受信任的包可跳过人工审核<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。提交者的包若未通过，最多有 35 天时间修复问题并重新提交<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。

关于通过 VirusTotal 使用的杀毒引擎数量，Chocolatey 自家材料的说法不一：社区仓库博客称超过 70 种扫描器，而文档 FAQ 则称通过 VirusTotal 合作使用 50 至 60 种扫描器<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。这一差异在厂商已发布的材料中未得到解决。

## 安全与供应链考量

自 CLI 0.9.10.0 起，Chocolatey 自身的二进制文件和 PowerShell 脚本均经过 Authenticode 签名，证书仅由 Chocolatey 员工（Chocolatey Software, Inc）持有<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。包可以要求对下载的软件进行校验和验证。

**审核仅反映审核时的状态。** 安全文档指出，审核和病毒检查反映的是原始审核时的包状态，除非包要求校验和，否则无法保证厂商不会更改包所用 URL 上提供的内容<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。文档还指出，包会交由 VirusTotal 检查，以对包及其包含或下载的底层软件的相对安全性提供另一份评估<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。

独立研究勾勒了更广泛的风险类别。2023 年 IEEE 安全与隐私研讨会的一篇论文识别了软件仓库及其客户端中的十二种潜在攻击向量，其中六种为首次披露，可被利用来隐蔽地分发恶意代码<sup>[9](https://doi.org/10.1109/sp46215.2023.10179332)</sup>。Springer 的一项关于应用程序安装程序和在线软件仓库的研究分析了连续 144 天收集的 2,935 个唯一 Windows 程序，发现在每个受评估仓库下载量前 100 的 Windows 程序中，存在易受攻击和/或被木马化的应用程序的痕迹<sup>[10](https://link.springer.com/chapter/10.1007/978-3-030-52683-2_10)</sup>。

厂商自身的指导是这方面最尖锐的实务表述：社区仓库仅占现有包总量的不到 5%（几乎所有包都是内部的），大多数使用 Chocolatey 的组织并不使用它，Chocolatey Software 不建议将其用于组织部署，而是推荐使用内部资源搭建的内部仓库<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。

## 企业部署与集成

当包及其资源托管在内部时，Chocolatey 可以在无互联网访问的情况下使用<sup>[6](https://chocolatey.org/how-chocolatey-works)</sup>。这正是厂商推荐给组织的模式：从社区源内部化或自行构建的包由组织控制的内部仓库提供<sup>[5](https://docs.chocolatey.org/en-us/information/security/)</sup>。请注意，在内部仓库上，社区仓库提供的验证器、核验器和扫描器服务并不存在，因此审查负担由组织自行承担<sup>[2](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)</sup>。

许多配置管理工具，包括 [Ansible](https://www.edgepedia.org/zh/ansible-software)、Chef、[Puppet](https://www.edgepedia.org/zh/puppet-software)、PowerShell DSC、Salt 等，都对 Chocolatey 有专门支持<sup>[6](https://chocolatey.org/how-chocolatey-works)</sup>，这使得现有的配置管理系统能够通过单一命令接口驱动 Windows 机群的软件安装。

## Chocolatey 数据一览与近期发展

CLI 的 2.x 系列在 2024 年持续推进。2024 年 6 月 5 日发布的 2.3.0 版本增加了在不移除固定版本包的情况下升级该包的能力<sup>[11](https://docs.chocolatey.org/en-us/choco/release-notes/)</sup>。2.4.0 版本将捆绑的 7zip 版本更新至 24.08，并移除了历史文件夹迁移逻辑<sup>[11](https://docs.chocolatey.org/en-us/choco/release-notes/)</sup>。近期版本借助社区贡献，在 `choco info` 输出中增加了软件安装路径，并显示用于安装包的源位置<sup>[12](https://github.com/chocolatey/choco/releases)</sup>。

在仓库方面，目录从 2024 年 5 月 30 亿次里程碑时的略低于 10,500 个唯一包，增长到 2025 年 8 月 27 日 40 亿次里程碑时的 10,905 个唯一包，版本总数达到 264,188 个<sup>[4](https://blog.chocolatey.org/2025/08/four-billion-installs/)</sup>。作为目录规模的参照，仓库自身列表页面上由社区维护的稳定包数量为 11,935 个<sup>[8](https://community.chocolatey.org/packages/)</sup>。

## References

1. [Tap the Chocolatey package manager to usher in Windows DevOps, TechTarget](https://www.techtarget.com/it-infrastructure/tip/Tap-the-Chocolatey-package-manager-to-usher-in-Windows-DevOps)
2. [What Is The Chocolatey Community Repository?, Chocolatey Software Blog (March 2024)](https://blog.chocolatey.org/2024/03/what-is-chocolatey-community-repository/)
3. [Chocolatey Software | Pricing](https://chocolatey.org/pricing)
4. [Four Billion Installs?, Chocolatey Software Blog (August 2025)](https://blog.chocolatey.org/2025/08/four-billion-installs/)
5. [Chocolatey Software Docs | Security](https://docs.chocolatey.org/en-us/information/security/)
6. [Chocolatey Software | How Chocolatey Works](https://chocolatey.org/how-chocolatey-works)
7. [Chocolatey Software | How Chocolatey Works (community courses)](https://community.chocolatey.org/courses/getting-started/how-chocolatey-works)
8. [Chocolatey Software | Packages](https://community.chocolatey.org/packages/)
9. [Investigating Package Related Security Threats in Software Registries, IEEE Symposium on Security and Privacy 2023](https://doi.org/10.1109/sp46215.2023.10179332)
10. [On the Security of Application Installers and Online Software Repositories, Springer](https://link.springer.com/chapter/10.1007/978-3-030-52683-2_10)
11. [Chocolatey CLI Release Notes](https://docs.chocolatey.org/en-us/choco/release-notes/)
12. [Releases · chocolatey/choco, GitHub](https://github.com/chocolatey/choco/releases)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Build, deployment, and development tooling › Package managers

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/chocolatey

English original: https://www.edgepedia.org/chocolatey
