macOS Sierra: Vagrant Quick Start Guide

John Foderaro
May 7, 2017 · 2 min read

This weekend I needed to get a test Linux environment up and running with minimal fuss. After not using a Vagrant managed virtual machine in some time, I decided to take a renewed approach in installing my dependencies via Homebrew.

Open Terminal and follow along!

1. Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL"

Once installed:

brew doctor
brew update

2. Install Virtual Box Cask

brew cask install virtualbox

3. Install Vagrant Cask

brew cask install vagrant

4. Create a Vagrant File

I like to keep my virtual machines in a seperate folder within my home directory, aptly titled “vms”:

mkdir ~/vms

From there, I create a folder per project (replace <project-name> with the actual name of the project:

mkdir ~/vms/<project-name>

In the project directory, add a custom Vagrantfile to get around the annoying “ubuntu” SSH issue that is currently happening in 16.04 with Vagrant and to also make the server available on whichever port of your choosing via http://localhost / (great when using ngrok to expose localhost via a secure tunnel to the Internet):

touch ~/vms/<project-name>/Vagrantfile

In your text editor of choice, open the newly created Vagrantfile and make appropriate edits to your port numbers on both your host and guest machines:

# -*- mode: ruby -*-
# vi: set ft=ruby :
VM_BOX = 'ubuntu/xenial64'
NETWORK = 'forwarded_port'
HOST_PORT = 9000
Vagrant.configure(2) do |config| = VM_BOX NETWORK, guest: GUEST_PORT, host: HOST_PORT
config.vm.provider "virtualbox" do |vb|
vb.memory = 1024
config.vm.provision 'shell', inline: <<-SHELL
echo 'ubuntu:ubuntu' | sudo chpasswd

Also take note that the password for the default ‘ubuntu’ user is changed to ‘ubuntu’ in a less than secure fashion (via this config file) using the shell script provisioning option. This is just a quick and simple way to get around the annoying SSH issue that seems to be impacting the official “ubuntu/xenial64” box. There are other advanced and more secure methods out there using SSH keys, so feel free to investigate as needed.

5. Vagrant Up and SSH

Now with the config file in place, navigate to the virtual machine project directory and run vagrant up

cd ~/vms/<project-name>
vagrant up

After a few minutes the virtual machine will be provisioned and will be accessible using either vagrant ssh (preferred method for access) or over usual ssh via ssh ubuntu@ -p 2222 with ubuntu/ubuntu as the credentials.

Enjoy what you’ve read?

Be sure to like and share below, or even buy me a coffee ☕️ !

John Foderaro is a JavaScript fanatic located in New Jersey.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store