Vagrant
What is Vagrant?
In this tutorial, you will create your first development environment with Vagrant. This quick start provides a brief introduction to Vagrant, its prerequisites, and an overview of three of the most important Vagrant commands to understand.
Vagrant isolates dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of your existing tools. To learn more about the benefits of Vagrant, read the "Why Vagrant?" introduction page.
The getting started tutorials use Vagrant with VirtualBox, since it is free and available on every major platform. Vagrant can work with many other providers.
Prerequisites
- Install the latest version of Vagrant.
- Install a virtualization product such as; VirtualBox, VMware Fusion, or Hyper-V.
VMware Fusion: There is an additional plugin and configuration required, review the documentation for guidance. Also, note that it is in tech preview for Apple Silicon.
Your first virtual machine
With the two commands below, you will have a fully usable virtual machine with Ubuntu 18.04 LTS 64-bit.
Initialize Vagrant
$ vagrant init hashicorp/bionic64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Before you can continue to the next step, ensure that Vagrant has created a Vagrantfile
.
$ ls -al
-rw-r--r-- 1 kaitlincarter staff 3024 13:07 Vagrantfile
Start the virtual machine
Now that you have a Vagrantfile
that configures your deployment, you can start the virtual machine.
$ vagrant up
When the virtual machine is successfully deployed, there will be a message stating that it is booted and ready.
==> default: Machine booted and ready!
==> default: Configuring network adapters within the VM...
==> default: Waiting for HGFS to become available...
==> default: Enabling and configuring shared folders...
Connect to the machine with vagrant ssh
and explore your environment.
Leave the SSH session with logout
.
Destroy the virtual machine
When you are done, be sure to terminate the virtual machine. Confirm when the CLI prompts you by typing y
.
$ vagrant destroy
==> default: Stopping the VMware VM...
==> default: Deleting the VM...
Next steps
Vagrant allows you to work on any project, to install every dependency that project needs, and to set up any networking or synced folders, so you can continue working from the comfort of your own machine.
You have just created your first virtual environment with Vagrant. Read on to learn more about project setup.