Vagrant: Quick Start

Vagrant is "an open-source software product for building and maintaining portable virtual software development environments" (https://en.wikipedia.org/wiki/Vagrant_(software)).

This post shows you how to setup and use Vagrant for the first time. You need to have VirtualBox installed beforehand.

install vagrant

On mac,

$ brew install vagrant

Here are the commands you will use in this post.

$ vagrant
Common commands:
     destroy         stops and deletes all traces of the vagrant machine
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login           
     ssh             connects to machine via SSH
     up              starts and provisions the vagrant environment


init

Choose the image from https://app.vagrantup.com/boxes/search, and give it to the init command.

$ vagrant init centos/7

This creates Vagrantfile on the current directory.
Open it and add the hostname and network. You may remove the comments.

vim Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = 'myhost'
  config.vm.network "private_network", ip: "192.168.11.8"
end


up

$ vagrant up


It will take a few minutes to download the image if the image has not been downloaded before.
Once up, you can see from VirtualBox UI that it is running.


ssh

$ vagrant ssh

Note: /vagrant/ directory is shared with the host machine.

$ ls /vagrant/ 
Vagrantfile


destroy

$ vagrant destroy

troubleshoot

In case you see "Permission denied" after creating a new user and ssh-ing into the host, see https://web-quickstart.blogspot.com/2021/04/ssh-permission-denied.html


Comments

Popular posts from this blog

Selenide: Quick Start

Minikube Installation for M1 Mac

Three.js Quick Start - Run Spinning-Cube Example