# Vagrant（软件）

**Vagrant** 是一款开源工具，用于构建和管理可移植、可复现的虚拟机开发环境，由一个名为 Vagrantfile 的声明式配置文件驱动。它构建在 [VirtualBox](https://www.edgepedia.org/zh/virtualbox)、VMware、Hyper-V 和 [Docker](https://www.edgepedia.org/zh/docker-software) 等虚拟化与容器平台之上，将原本需要在每位开发者机器上手动完成、容易出错的配置过程，变成一条命令 `vagrant up`，从而为团队中的每一位成员生成完全相同的工作环境。<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup><sup> • </sup><sup>[2](https://developer.hashicorp.com/vagrant/docs/boxes)</sup>

| 关键事实 | 详情 |
|---|---|
| 用途 | 在多名开发者之间复制一致的开发环境，通过共享配置文件固定软件库版本、环境变量和依赖项<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup> |
| 包格式 | Box：针对特定提供者的虚拟机镜像；同一个 box 在任何受支持的平台上都能生成相同的环境<sup>[2](https://developer.hashicorp.com/vagrant/docs/boxes)</sup><sup> • </sup><sup>[3](https://developer.hashicorp.com/vagrant/docs/providers/basic_usage)</sup> |
| 内置提供者 | VirtualBox、Hyper-V 和 Docker；其他提供者（包括 VMware 和 libvirt）通过插件系统安装<sup>[4](https://docs.hashicorp.com/vagrant/docs/providers)</sup> |
| 规模 | GitHub 星标约 27,200，复刻约 4,400，仓库创建于 2010 年 1 月 21 日；据创建者米切尔·桥本（Mitchell Hashimoto）称，每年下载量约为 400 万至 500 万次<sup>[5](https://github.com/hashicorp/vagrant)</sup><sup> • </sup><sup>[6](https://www.heavybit.com/library/podcasts/enterpriseready/ep-29-achieving-ubiquity-with-mitchell-hashimoto-of-hashicorp)</sup> |
| 注册表 | Vagrant Cloud 已迁移至 HCP Vagrant 注册表；HCP Vagrant 正在被弃用；新的 box 和注册表创建已于 2026 年 10 月 1 日终止，客户必须自行重新托管其 box<sup>[7](https://www.hashicorp.com/en/blog/vagrant-cloud-is-moving-to-hcp)</sup><sup> • </sup><sup>[8](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)</sup> |
| 维护 | 2.4.9 版于 2025 年 8 月 21 日发布，新增对 VirtualBox 7.2 的支持<sup>[9](https://github.com/hashicorp/vagrant/blob/v2.4.9/CHANGELOG.md)</sup> |
| 许可证 | 2023 年变更为商业源代码许可证（BSL）<sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup> |

## 概述

Vagrant 解决了软件开发环境中的一致性问题。当每位开发者手动配置虚拟机时，语言、库和环境变量的版本会逐渐产生差异，同一个 bug 可能在某台机器上出现，在另一台机器上却不出现。Vagrant 则通过在仓库中签入的 Vagrantfile 来描述环境：它指定基础 box，定义网络和同步文件夹，并规定配置步骤。每位团队成员运行 `vagrant up`，就能得到完全相同的环境。<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup><sup> • </sup><sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup>

与直接操作 VirtualBox 相比，Vagrant 增加了可脚本化和可移植性。一个开设大规模开放在线课程的研究小组这样描述两者的分工：Vagrant 为生成虚拟机镜像（即 box）提供可脚本化能力，而 VirtualBox 确保结果能够移植到大多数操作系统上，从而将原本需要在每位学习者机器上手动完成、容易出错的配置自动化。<sup>[11](https://pdfs.semanticscholar.org/6385/adb74b9259ccf097d4dc5cf9abd2ebf60cbb.pdf)</sup> Vagrant 环境可运行于 Windows、macOS 和 Linux。<sup>[12](https://stackshare.io/stackups/docker-compose-vs-vagrant)</sup>

## 历史

**源于咨询工作的痛点。** [米切尔·桥本](https://www.edgepedia.org/zh/mitchell-hashimoto)在 [Ruby on Rails](https://www.edgepedia.org/zh/ruby-on-rails) 咨询公司工作时编写了 Vagrant，当时大约每六周就会有新项目到来。切换到另一位客户的项目时，配置环境可能浪费半天时间，而且配置过程还可能破坏开发者已有的配置；Vagrant 消除了这一无法计费的时间消耗。<sup>[13](https://newsletter.pragmaticengineer.com/p/mitchell-hashimoto)</sup><sup> • </sup><sup>[14](https://thenewstack.io/new-stack-makers-mitchell-hashimoto-vagrant-containers-growing-open-source/)</sup> 该工具最初考虑过的一些名称包括 BoxCutter 和 Hobo。<sup>[15](https://changelog.com/podcast/88)</sup>

GitHub 仓库可追溯至 2010 年 1 月 21 日。<sup>[5](https://github.com/hashicorp/vagrant)</sup> 桥本后来成立了 [HashiCorp](https://www.edgepedia.org/zh/hashicorp)，全职投入 Vagrant 的开发。<sup>[15](https://changelog.com/podcast/88)</sup> 他指出，Vagrant 在构建时并没有考虑云；目标只是快速启动一个项目的依赖项并开始工作，直到后来它才被证明对云工具也有用。<sup>[6](https://www.heavybit.com/library/podcasts/enterpriseready/ep-29-achieving-ubiquity-with-mitchell-hashimoto-of-hashicorp)</sup>

## 工作原理

Vagrantfile 是一个声明机器的配置文件：使用哪个 box、网络设置、同步文件夹以及配置器。配置器在 Vagrantfile 中配置，并在首次执行 `vagrant up` 时运行，在刚刚启动的机器上安装软件并应用配置。Vagrant 可以结合 shell 脚本或 [Ansible](https://www.edgepedia.org/zh/ansible-software)、[Puppet](https://www.edgepedia.org/zh/puppet-software)、Chef 等自动化工具来执行配置任务。<sup>[16](https://delftswa.github.io/chapters/vagrant/index.html)</sup><sup> • </sup><sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup>

日常生命周期很短：`vagrant up` 启动并配置机器，`vagrant ssh` 打开一个进入该机器的 shell。除了单机之外，Vagrant 还支持在一个 Vagrantfile 中定义的多机环境，此时 `vagrant ssh` 等命令需要指定目标机器的名称。其他功能包括：用 `vagrant package` 将运行中的环境打包为 box、在宿主机与客户机之间共享目录的同步文件夹，以及端口转发和私有、公共网络选项。<sup>[16](https://delftswa.github.io/chapters/vagrant/index.html)</sup>

一台机器只在一个提供者下运行，不过多机环境中的不同机器可以使用不同的提供者。提供者的选择顺序是：如果 `vagrant up` 带有 `--provider` 标志，则使用该标志；否则使用 `VAGRANT_DEFAULT_PROVIDER` 环境变量；再否则由 Vagrant 的检测逻辑决定。<sup>[3](https://developer.hashicorp.com/vagrant/docs/providers/basic_usage)</sup>

## Box 与分发

Box 是 Vagrant 环境的包格式。Vagrantfile 指定 box 及其运行配置，同一个 box 可以在任何受支持的平台上使用，以启动相同的工作环境。Box 需要提供者（一种虚拟化产品）才能运行。<sup>[2](https://developer.hashicorp.com/vagrant/docs/boxes)</sup>

Box 是特定于提供者的：为 VirtualBox 构建的 box 与 VMware 提供者或任何其他提供者不兼容，而不同提供者的 box 可能同名。Vagrant 会自动检测 box 适用于哪个提供者。<sup>[3](https://developer.hashicorp.com/vagrant/docs/providers/basic_usage)</sup>

公共目录涵盖大多数主流操作系统，以及 LAMP 套件等专用 box。官方仅推荐两套 box：HashiCorp 的精简版 Ubuntu 18.04 64 位 box，针对小体积进行了优化，可用于 VirtualBox、Hyper-V 和 VMware；以及开源的 Bento box，为 VMware、VirtualBox 和 [Parallels](https://www.edgepedia.org/zh/parallels) 构建。<sup>[2](https://developer.hashicorp.com/vagrant/docs/boxes)</sup>

分发权已两次易手。Vagrant Cloud 的功能已迁移至 HashiCorp 云平台，成为 HCP Vagrant 注册表；HashiCorp 免费托管公共和私有 box，并在停用 Vagrant Cloud 应用之前自动迁移属于不活跃用户的 box。<sup>[7](https://www.hashicorp.com/en/blog/vagrant-cloud-is-moving-to-hcp)</sup> 目录元数据保留 box 版本、提供者、架构、下载 URL 和校验和，正是这些信息让 `vagrant up` 能够可复现地获取固定版本。<sup>[8](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)</sup>

## 提供者

Vagrant 内置对 VirtualBox、Hyper-V 和 Docker 的支持。其他机器类型通过 Vagrant 插件系统安装的第三方提供者来管理，VMware 和 libvirt 支持就是这样提供的。<sup>[4](https://docs.hashicorp.com/vagrant/docs/providers)</sup><sup> • </sup><sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup>

在性能方面，HashiCorp 自己的文档推荐在实际工作中使用 VMware 提供者，称其得到良好支持，通常比 VirtualBox 更稳定、性能更好。<sup>[4](https://docs.hashicorp.com/vagrant/docs/providers)</sup> 默认情况下，Vagrant 使用 VirtualBox。<sup>[16](https://delftswa.github.io/chapters/vagrant/index.html)</sup>

## 数据一览

hashicorp/vagrant 仓库约有 27,200 个星标和 4,400 个复刻，创建于 2010 年 1 月 21 日。主要贡献者是米切尔·桥本（5,974 次贡献）和克里斯·罗伯茨（Chris Roberts，3,236 次贡献）。<sup>[5](https://github.com/hashicorp/vagrant)</sup> 桥本在一次采访中表示，Vagrant 每年仍有约 400 万至 500 万次下载。<sup>[6](https://www.heavybit.com/library/podcasts/enterpriseready/ep-29-achieving-ubiquity-with-mitchell-hashimoto-of-hashicorp)</sup> 维护工作以缓慢的节奏持续进行：2025 年 8 月 21 日发布的 2.4.9 版新增了对 VirtualBox 7.2 的支持，并修复了 Ansible 配置器在类 RHEL 系统上的操作系统检测问题。<sup>[9](https://github.com/hashicorp/vagrant/blob/v2.4.9/CHANGELOG.md)</sup>

## 对比

**Vagrant 与 Docker Compose。** Docker Compose 创建并管理多容器 Docker 应用，而 Vagrant 配置的是虚拟机而非容器。容器轻量，共享宿主系统的内核，资源占用更少、启动更快；Vagrant 的虚拟机在内存和存储方面更重，但提供更高程度的隔离。<sup>[12](https://stackshare.io/stackups/docker-compose-vs-vagrant)</sup>

**Vagrant 与 Terraform。** HashiCorp 划出了一条明确的界线：Vagrant 是专注于管理开发环境的工具，Terraform 是构建基础设施的工具。Terraform 的主要用途是管理 AWS 等云提供者中的远程资源，规模可达横跨多个云的超大型基础设施；而 Vagrant 是为最多只有几台虚拟机的本地开发环境而设计的。Vagrant 还提供 Terraform 所缺少的功能，包括同步文件夹、自动网络和 HTTP 隧道。<sup>[17](https://developer.hashicorp.com/vagrant/intro/vs/terraform)</sup>

**Vagrant 与 Ansible，以及 Packer 的搭配。** 这三款与 HashiCorp 相关的工具是互补而非竞争的：一个组织可以用 Ansible 进行网络配置管理，用 Terraform 管理云基础设施生命周期，用 Vagrant 实现开发和测试平台的标准化。<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup> 一种常见的模式是将 Packer 与 Vagrant 搭配使用：Packer 构建机器镜像（“是什么”），Vagrant 从这些镜像配置虚拟机（“怎么做”），Packer 生成黄金镜像，Vagrant 处理特定于项目的配置。<sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup>

## 近期动态

**许可证。** 2023 年，HashiCorp 将 Vagrant 的许可证变更为商业源代码许可证（BSL）。<sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup>

**注册表变动。** 在 Vagrant Cloud 迁移至 HCP Vagrant 注册表之后，<sup>[7](https://www.hashicorp.com/en/blog/vagrant-cloud-is-moving-to-hcp)</sup> HashiCorp 宣布弃用 HCP Vagrant 本身。新的 box 和注册表创建将于 2026 年 10 月 1 日终止；支持与维护将于 2026 年 11 月 2 日终止；所有剩余部署将于 2026 年 12 月 31 日退役。<sup>[8](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)</sup> 此次弃用仅适用于 HCP Vagrant：Vagrant CLI 及其 GitHub 源代码仓库仍然可用，但客户必须自行重新托管其 box 并承担托管成本，HashiCorp 指向了 AWS、IBM Cloud 和 Azure 的存储定价。<sup>[8](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)</sup><sup> • </sup><sup>[18](https://discuss.hashicorp.com/t/deprecation-of-hcp-vagrant/77619)</sup> 2026 年 10 月 1 日之后，用户仍可使用 Vagrant CLI 创建 box，但无法通过 HCP Vagrant 或 Vagrant 公共注册表接口创建或分享 box。<sup>[18](https://discuss.hashicorp.com/t/deprecation-of-hcp-vagrant/77619)</sup> HashiCorp 提供了多种迁移路径，包括本地导出 box、在 [Amazon S3](https://www.edgepedia.org/zh/amazon-s3) 中托管 box 的指南，以及使用 URL 重定向的静态归档方案；替代仓库必须同时提供 .box 文件和目录元数据，并保留版本、提供者、架构、下载 URL 和校验和。<sup>[8](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)</sup> 在社区讨论中，成员提议建立一个类似 artifacthub.io 的社区运营共享目录，用于 Vagrant box，让人们无需中央主机即可分享 box。<sup>[18](https://discuss.hashicorp.com/t/deprecation-of-hcp-vagrant/77619)</sup> 仓库本身附有一则通知，称自 2026 年 11 月 2 日起，社区版将只提供有限功能，且该变更不适用于 Vagrant CLI。<sup>[5](https://github.com/hashicorp/vagrant)</sup>

## 实际应用与批评

Vagrant 已被用于在大规模开放在线课程中大规模提供虚拟机实操练习，脚本化 box 生成与 VirtualBox 可移植性的结合，让每位学习者都能在本地复现实验环境。<sup>[11](https://pdfs.semanticscholar.org/6385/adb74b9259ccf097d4dc5cf9abd2ebf60cbb.pdf)</sup> 在团队环境中，标准工作流程是将 Vagrantfile 提交到仓库，让每位成员运行 `vagrant up` 以获得相同的环境。<sup>[10](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)</sup>

有据可查的局限性是具体的。由于 Vagrant 配置多台虚拟机，而虚拟机资源消耗大，因此它会占用大量内存和 CPU，并增加复杂性；它比其他配置管理工具更慢；它无法实施生产基础设施变更，那是 Terraform 的领域。<sup>[1](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)</sup> Kameleon 项目背后的研究人员补充了一条结构性批评：Vagrant 对预构建镜像的依赖妨碍了对操作系统层的理解，并使该层的修改变得困难，当团队需要控制操作系统本身而不仅仅是其上的软件时，这一点尤为重要。<sup>[19](https://dl.acm.org/doi/pdf/10.1145/2723872.2723883)</sup>

## References

1. [Ansible vs. Terraform vs. Vagrant: What's the difference? (TechTarget)](https://www.techtarget.com/it-infrastructure/tip/Ansible-vs-Terraform-vs-Vagrant-Whats-the-difference)
2. [Vagrant Boxes | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/boxes)
3. [Basic Usage - Providers | Vagrant | HashiCorp Developer](https://developer.hashicorp.com/vagrant/docs/providers/basic_usage)
4. [Providers | Vagrant | HashiCorp Developer](https://docs.hashicorp.com/vagrant/docs/providers)
5. [hashicorp/vagrant (GitHub repository)](https://github.com/hashicorp/vagrant)
6. [EnterpriseReady Ep. #29: Mitchell Hashimoto of HashiCorp (Heavybit)](https://www.heavybit.com/library/podcasts/enterpriseready/ep-29-achieving-ubiquity-with-mitchell-hashimoto-of-hashicorp)
7. [Vagrant Cloud is moving to HCP (HashiCorp blog)](https://www.hashicorp.com/en/blog/vagrant-cloud-is-moving-to-hcp)
8. [HCP Vagrant deprecation: important dates and migration guidance (HashiCorp blog)](https://www.hashicorp.com/en/blog/hcp-vagrant-deprecation-important-dates-and-migration-guidance)
9. [Vagrant CHANGELOG (v2.4.9)](https://github.com/hashicorp/vagrant/blob/v2.4.9/CHANGELOG.md)
10. [Self-Hosted Dev Environment Tools: Packer vs Vagrant vs Multipass Guide 2026 (Pi Stack)](https://www.pistack.xyz/posts/2026-05-20-self-hosted-dev-environment-tools-packer-vagrant-multipass-guide/)
11. [Vagrant Virtual Machines for Hands-On Exercises in MOOCs (Staubitz et al., 2016)](https://pdfs.semanticscholar.org/6385/adb74b9259ccf097d4dc5cf9abd2ebf60cbb.pdf)
12. [Vagrant vs Docker Compose (StackShare)](https://stackshare.io/stackups/docker-compose-vs-vagrant)
13. [Mitchell Hashimoto's new way of writing code (The Pragmatic Engineer)](https://newsletter.pragmaticengineer.com/p/mitchell-hashimoto)
14. [The New Stack Makers: Mitchell Hashimoto on Vagrant, Containers and Growing Up with Open Source](https://thenewstack.io/new-stack-makers-mitchell-hashimoto-vagrant-containers-growing-open-source/)
15. [Vagrant and HashiCorp (Changelog Interviews #88)](https://changelog.com/podcast/88)
16. [Vagrant: Development environments made easy (Delft SWA chapter)](https://delftswa.github.io/chapters/vagrant/index.html)
17. [Vagrant vs. Terraform | HashiCorp Developer](https://developer.hashicorp.com/vagrant/intro/vs/terraform)
18. [Deprecation of HCP Vagrant (HashiCorp Discuss)](https://discuss.hashicorp.com/t/deprecation-of-hcp-vagrant/77619)
19. [Reconstructable Software Appliances with Kameleon (ACM)](https://dl.acm.org/doi/pdf/10.1145/2723872.2723883)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms › Cloud, virtualization, and containers

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/vagrant-software

English original: https://www.edgepedia.org/vagrant-software
