How To - Vagrant
Website: vagrantup.com
Vagrant Documentation: vagrantup.com/docs
Pre-requisite
We need a hypervisor installed on the machine where we want to install Vagrant. We will be using Virtualbox but you can use VMWare or any other provider.
brew install --cask virtualbox
Virtualbox requires a kernel extension to work. If the installation fails, retry after you enabling it in:
System Preferences → Security & Privacy → General
Install Vagrant
brew install --cask vagrant
Verify the Installed Vagrant Version
This command will also show latest version of Vagrant available along with the installed version.
vagrant version
Create a Directory for Storing Vagrant files
mkdir vagrant_directory
cd vagrant_directory
Initialize Vagrant Box
vagrant init hashicorp/bionic64
List Vagrant Box Files
vagrant box list
Start the Virtual Machine
vagrant up
Login to Virtual Machine Shell
vagrant ssh
Show Port Mapping
This will display the full list of guest ports mapped to the host machine ports.
vagrant port
Suspend the Virtual Machine
Suspending the virtual machine will stop it and save its current running state.
vagrant suspend
Halt the Virtual Machine
Halting the virtual machine will gracefully shut down the guest operating system and power down the guest machine.
vagrant halt
Terminate the Virtual Machine
Destroying the virtual machine will remove all traces of the guest machine from your system. It'll stop the guest machine, power it down, and reclaim its disk space and RAM.
vagrant destroy
Remove the Vagrant Box File
vagrant box remove hashicorp/bionic64
GUI Search Options for Vagrant Boxes
- Go to the app.vagrantup.com/boxes/search
- Put the name of the OS/application you are searching for in the search field, for example here we will write centos then select virtualbox as the hypervisor and click on search icon, results will be shown for the search string centos. Select the Centos/7.
- On the details page click on new tab to get the commands to download the box and launch it.