Vagarant quick start guide on Mac

Vagrant is an excellent tool to create and configure lightweight, reproducible, and portable development environments. Here is a quick start guide to use vagrant on Mac. We’ll install centos virtual machine on Mac using Virtualbox.

  1. Download and Instal Virtualbox from Oracle Virtualbox site.
  2. Install vagrant using brew
    $ brew cask install vagrant
    $ brew cask info vagrant
    /usr/local/Caskroom/vagrant/1.8.5 (3 files, 85.6M)
    ==> Name
    ==> Artifacts
    Vagrant.pkg (pkg)
  3. Add an image (e.g. centos 6.6 image) to vagrant boxes
    $ vagrant box add centos66
  4. List vagrant boxes
    $ vagrant box list
    centos66  (virtualbox, 0)
    centos7   (virtualbox, 0)
    precise64 (virtualbox, 0)
  5. Initialize a new Vagrant environment by creating a Vagrantfile
    $ mkdir -p ~/vagrant/centos66
    $ cd ~/vagrant/centos66
    $ vagrant init centos66 ## This will create Vagrantfile
  6. To allow ssh using default vagrant insecure key ~/.vagrant.d/insecure_private_key add the following line to Vagrantfile before end
    config.ssh.insert_key = false

    This should be avoided if your project needs security.

  7. starts and provisions the vagrant environment
    $ vagrant up
  8. connects to machine via SSH
    $ vagrant ssh-config ## This will print ssh config which is used to connect to the machine
    $ vagrant ssh

    This should login using private key (as per the setup above). Default password for user vagrant is vagrant in case the private key does not work.

  9. halt machine
    $ vagrant halt
  10. stops and deletes all traces of the vagrant machine
    $ vagrant destroy  ## From the same dir where Vagrantfile is present
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments