Install Vagrant:
# Example for Debian/Ubuntu
sudo apt-get update
sudo apt-get install vagrant
# Example for macOS (using Homebrew)
brew install vagrant
A comprehensive cheat sheet for Vagrant, covering essential commands, Vagrantfile configuration, and best practices to streamline your virtual environment development.
|
Install Vagrant:
|
|
Verify Installation:
|
|
Install VirtualBox (if not already installed): Vagrant relies on a provider like VirtualBox or VMware. VirtualBox is a common open-source option.
|
|
|
Initializes a new Vagrant environment by creating a Example: |
|
|
Starts the Vagrant virtual machine. It reads the Example: |
|
|
Connects to the Vagrant virtual machine via SSH. Example: |
|
|
Stops the running Vagrant virtual machine gracefully. Example: |
|
|
Suspends the Vagrant virtual machine, saving its current state to disk. Example: |
|
|
Resumes a suspended Vagrant virtual machine. Example: |
|
Adding a box is how Vagrant knows what OS template to use. Official boxes can be found on HashiCorp’s Atlas.
Example: |
|
The |
|
Basic
|
|
Port Forwarding |
Forwards a port from the host machine to the guest machine.
|
|
Private Network (Static IP) |
Configures a static IP address for the guest machine on a private network.
|
|
Public Network (Bridged) |
Bridges the guest machine to your host’s network, giving it an IP address on your local network.
|
|
Shell Provisioning |
Runs a shell script to automate the setup of the guest machine.
|
|
Ansible Provisioning |
Uses Ansible to provision the guest machine.
|
|
Puppet Provisioning |
Uses Puppet to provision the guest machine.
|
|
Synced folders allow you to share files between your host machine and the Vagrant guest machine. By default, the Vagrantfile directory is synced to |
|
Configuring synced folders:
|
|
NFS Synced Folders: For better performance, especially on macOS, you can use NFS synced folders.
|
|
Vagrant allows you to define and manage multiple virtual machines within a single |
|
Defining multiple machines:
|
|
Accessing specific machines:
|
|
|
Lists all installed boxes. Example: |
|
|
Removes a specified box from your system. Example: |
|
|
Checks for updates for installed boxes and installs them. Example: |
|
Networking Conflicts: |
|
Provider Issues: |
|
Synced Folder Permissions: |
|
|
Installs a Vagrant plugin. Example: |
|
|
Lists installed Vagrant plugins. Example: |
|
|
Uninstalls a Vagrant plugin. Example: |
|
Use a Version Control System: |
|
Customize Guest Machine Hostname:
|
|
Optimize Performance: |