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.
- Download and Instal Virtualbox from Oracle Virtualbox site.
- Install vagrant using brew
$ brew cask install vagrant $ brew cask info vagrant https://www.vagrantup.com/ /usr/local/Caskroom/vagrant/1.8.5 (3 files, 85.6M) From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/vagrant.rb ==> Name Vagrant ==> Artifacts Vagrant.pkg (pkg)
- Add an image (e.g. centos 6.6 image) to vagrant boxes
$ vagrant box add centos66 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
- List vagrant boxes
$ vagrant box list centos66 (virtualbox, 0) centos7 (virtualbox, 0) precise64 (virtualbox, 0)
- Initialize a new Vagrant environment by creating a Vagrantfile
$ mkdir -p ~/vagrant/centos66 $ cd ~/vagrant/centos66 $ vagrant init centos66 ## This will create Vagrantfile
- 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.
- starts and provisions the vagrant environment
$ vagrant up
- 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.
- halt machine
$ vagrant halt
- stops and deletes all traces of the vagrant machine
$ vagrant destroy ## From the same dir where Vagrantfile is present