vagrant up!

I’ve decided to continue my break from Rust by exploring some Rails development with Vagrant and VirtualBox.

I’m going to go throug the Getting Started process on Vagrant’s Website and write down what happens.

Step 0: I installed VirtualBox from their website choosing defaults in the wizard. Nothing to see here.

Step 1: Make a new directory, change to it, git init so I can go backwards if I mess up, then:

vagrant init hashicorp/precise64

The nice little console prompt says that I can just vagrant up now and I’ll have a box running. Let’s try it!

Bringing machine 'default' up with 'virtualbox' provider... and then it starts to download a bunch of stuff. Time to get some tea.

Quick aside, while I’m waiting for this to download: if you’re wondering where this .box file is going, I found a helpful StackOverflow Question that says where, with a helpful comment that says how to change where: Set an environment variable: VAGRANT_HOME=D:\.vagrant.d

Note to self: get a better internet service provider.

Anyway, the powershell output basically says, “hey, you’ve initiated a new box. Awesome. We don’t have an image cached for that box, so we’re going to go download it from hashicorp’s website.” So far, so good.

After the VM base image is downloaded, Vagrant boots the VM and configures port forwarding so that I can SSH into the box. The first time I booted the VM, some things updated and the VM restarted once.

Step 2: vagrant up — This command will boot the vm. (Note that the previous command already booted the VM. vagrant up is just how you get back here, and vagrant status is how you check whether the VM is running.):

==> default: Machine booted and ready!

That sounds like good news. Let’s take a look around. Typing vagrant ssh from powershell complains that it can’t find an SSH client on my machine, but I already have git bash installed, so I’ll just try using that. Note that you need to be in the right directory to SSH.

$ pwd 
/my_project/rootdirectory 
$ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) 
vagrant@precise64:$ pwd 
/home/vagrant 
vagrant@precise64:$ ls 
postinstall.sh

Ok cool. We’re in a newly built vm, in a folder at /home/vagrant, and there’s a script called postinstall.sh. I decided to run this script. There’s nothing about it in the Getting Started website so far. There were a lot of permissions errors, and it erased itself when it was done. (Note to self: next time you re-image this VM, edit the script so it sticks around and you can look at it.)

Step 3: Folder magic

So far the feature I find coolest with Vagrant is syncing folders. Inside the VM, the folder /vagrant syncs with the root of the project on the host OS. Let’s prove it.

vagrant@precise64:$ vim /vagrant/blog1.md

Vim is not installed. Bummer.

vagrant@precise64:$ sudo apt-get install vim

Lots of missing package errors.

vagrant@precise64:$ sudo apt-get install vim --fix-missing

More of the same

vagrant@precise64:$ sudo apt-get update

Lots of stuff scrolls by, and now vagrant@precise64:$ sudo apt-get install vim succeeds, so I

vagrant@precise64:$ vim /vagrant/blog1.md

And now I’m in insert mode editing this blog about Vagrant from inside a VM on Vagrant, and when I write the file, it changes in Windows. Awesome.

The whole thing took less than an hour (including tea and downloading things). Next time, we’ll take a look at getting something more complicated working in here.

Till then, happy learning (from inside a vagrant box!)

-Will

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s