# Vagrant
> Build and manage reproducible virtual machine environments

## Summary
Tool for building, configuring, and managing reproducible virtual machine environments using a simple declarative Vagrantfile with support for VirtualBox, VMware, Docker, and other providers.

## Capabilities
- Create and configure virtual machines from a Vagrantfile
- Provision VMs with shell scripts, Ansible, Chef, or Puppet
- Share and distribute pre-built VM images (boxes)
- Sync folders between host and guest machines
- Configure networking, forwarded ports, and multi-machine setups
- Support multiple providers including VirtualBox, VMware, and Docker

## When to Use
- Setting up reproducible development environments across a team
- Need isolated virtual machines for testing or development
- Building multi-machine environments that mirror production
- Want declarative VM configuration checked into version control

## When NOT to Use
- Working with containers (use Docker or Podman instead)
- Need lightweight ephemeral environments without full VMs
- Running on machines without virtualization support

## Key Flags
- `up`: Create and configure the virtual machine
- `ssh`: Connect to the machine via SSH
- `halt`: Shut down the running machine
- `destroy`: Stop and delete the machine and its resources
- `provision`: Run the configured provisioners
- `snapshot save`: Take a snapshot of the current machine state

## Usage Patterns
### Initialize and start a VM
```
vagrant init ubuntu/jammy64 && vagrant up
```
Creates a Vagrantfile with Ubuntu 22.04 and boots the VM

### SSH into a running VM
```
vagrant ssh
```
Opens an SSH session to the default machine

### Destroy and recreate from scratch
```
vagrant destroy -f && vagrant up
```
Tears down the VM and provisions a fresh one

### Take and restore a snapshot
```
vagrant snapshot save clean-state
```
Saves the current VM state for later restoration

## Input / Output
- **stdin**: Accepts confirmation input for destructive operations
- **stdout**: VM status, provisioning output, and SSH session
- **stderr**: Error messages and provider warnings

## Installation
- **homebrew**: `brew install vagrant`

## Related Tools
- [docker](/tools/docker) (alternative): Docker provides lightweight containers; Vagrant manages full virtual machines
- [pulumi](/tools/pulumi) (complementary): Pulumi manages cloud infrastructure; Vagrant manages local VMs
- [distrobox](/tools/distrobox) (alternative): Distrobox uses containers for development environments instead of VMs

---
Source: https://littlescripts.sh/tools/vagrant
