Recently, I was trying to start working on my website again. I had created it using Middleman. As I was trying to set it up I ran into a couple of issues, mainly due ruby issues on Windows.
So I decided to use Vagrant to create a reference environment for the project, and it couldn't have been easier.
- Install VirtualBox or any provider which Vagrant supports)
- Install Vagrant
- A basic Middleman project, see here
Setup your Vagrant VM
Create the directory for your project and open a command prompt to that path.
Run the following command to generate a Vagrantfile:
A Vagrantfile is basically a configuration file for your Vagrant VM. Mine ends up looking something like this:
# -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 4567, host: 4567 end
Obviously, you can customize this to your needs
Next, we'll setup a provisioning script so we can tell the VM to install packages. We're going to use the shell provisioner for this tutorial. It's the simplest provisioner to use, and is easy to wrap your head around if it's your first time using Vagrant. Basically, it runs a shell script as root during the provisioning process.
Create the file bootstrap.sh and paste the following into it:
#!/usr/bin/env bash apt-get update apt-get install -y build-essential ruby1.9.3 libxslt1-dev libxml2-dev gem install bundler
This will install a few required packages from apt as well as the bundler gem (system-wide).
To tell Vagrant to use the script for provisioning add the following line to your Vagrantfile, right before the end keyword:
config.vm.provision :shell, :path => "bootstrap.sh"
Start the VM
Issue the following command to build, provision and start the VM.
SSH into the VM
If you are on OSX or Linux, issue the following command to SSH into the VM:
If you're on Windows you'll need to install PuTTY or something like it in order to SSH into the VM. Vagrant's private key is located in your home directory under .vagrant.d/insecure_private_key.
Once you're SSH'd into the machine, move to Vagrant's shared folder
Now you'll use bundler to install the required gems:
Now you should be able to run middleman to serve the site