Up and Running With Vagrant

Umesh Yadav
Sep 9, 2018 · 2 min read

Vagrant is an open-source software product for building and maintaining portable virtual software development environments. Vagrant is written is ruby and is maintained by Hashicorp. It helps you build and launch reusable virtual machines using Vagrantfile.

Install Vagrant on Mac

To install vagrant on mac you can just simply run the following command. In order to successfully use vagrant, you need to first install virtualbox.

Install virtualbox:

$ brew cask install virtualbox

Install vagrant:

$ brew cask install vagrant

For other platform please refer this link.

Now you have vagrant installed on your laptop. Let’s launch your first virtual box.

Create Vagrantfile

Vagrantfile is configuration file for your virtual machine this helps to build and manage virtual machine.

Let’s create our first vagrantfile. Create a file named Vagrantfile in your ~/Vagrantfiles/ubuntu/.

Vagrant.configure(2) do |config|config.vm.box = "ubuntu/xenial64"config.vm.network "forwarded_port", guest: 80, host: 9000config.vm.provider "virtualbox" do |vb|vb.memory = 1024endconfig.vm.provision 'shell', inline: <<-SHELLecho 'ubuntu:ubuntu' | sudo chpasswdSHELLend

In the above example we are creating a ubuntu machine with 1024 mb ram and with username and password ubuntu. Once this is done, let’s start our virtual machine.

Getting ubuntu machine up and running

In order to get your virtual machine up and running you need to just go to the directory under which the vagrantfile is situated.

$ cd ~/Vagrantfiles/ubuntu/
$ vagrant up

By now you will have your ubuntu machine up and running. To use your machine you need to simply ssh into the machine using the following command.

$ vagrant ssh

This is it for now. To know more about vagrant please stay tuned to my blogs.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade