Skip to content
Home » Learning more about Vagrant

Learning more about Vagrant

Vagrant is an open-source tool developed by HashiCorp for building and managing virtualized development environments in a consistent and automated way. It enables developers to create portable and reproducible virtual machines or containers, known as “boxes,” that encompass everything required for a project, including the operating system, software dependencies, and configurations.

Vagrant installation in Windows

The installation link is here https://developer.hashicorp.com/vagrant/install. I chose the AMD64 version following the wizard. Once installed, you can verify that it was installed by typing vagrant from a PowerShell command line.

VirtualBox installation

The installation link is here https://www.virtualbox.org/wiki/Downloads. I chose the Windows hosts package. Once installed, you will have the Oracle VirtualBox Administrator.

Vagrant configuration (console mode)

You can use the command vagrant init inside your project directory to create a Vagrantfile template. On that template, the box must be indicated. The list of boxes is shown here: https://portal.cloud.hashicorp.com/vagrant/discover. For example, this configuration:

config.vm.box = "ubuntu/bionic64"

Below is an example of network settings to be configured

config.vm.network "private_network", ip: "192.168.33.10"

Below is an example of the configuration for the provider

config.vm.provider "virtualbox" do |vb|
     vb.memory = "1024"
	 vb.cpus = 2
   end

To start the VM, use the following command

vagrant up

To connect to the VM, use the following command. Ready to use it.

vagrant ssh

Vagrant configuration (graphic mode)

Below is the change for graphical mode.

config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
vb.gui = true
#
# # Customize the amount of memory on the VM:
vb.memory = "10024"
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end

# to make synced folder works.
  config.vm.synced_folder ".", "/vagrant", type: "virtualbox"

  # Add Google Chrome repository
  config.vm.provision :shell, inline: "wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub|sudo apt-key add -"
  config.vm.provision :shell, inline: "sudo sh -c 'echo \"deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main\" > /etc/apt/sources.list.d/google.list'"

  # Update repositories
  config.vm.provision :shell, inline: "sudo apt update -y"

  # Upgrade installed packages
  config.vm.provision :shell, inline: "sudo apt upgrade -y"

  # Add desktop environment
  config.vm.provision :shell, inline: "sudo apt install -y --no-install-recommends ubuntu-desktop"
  config.vm.provision :shell, inline: "sudo apt install -y --no-install-recommends virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11"
  # Add `vagrant` to Administrator
  config.vm.provision :shell, inline: "sudo usermod -a -G sudo vagrant"

  # Add Google Chrome
  config.vm.provision :shell, inline: "sudo apt install -y google-chrome-stable"

  # Restart
  config.vm.provision :shell, inline: "sudo shutdown -r now"
  #

In my opinion, this tool is easy to use. I recommend taking a look at that because you can have a virtual machine configured according to your needs.

Thanks for reading this blog.