In the blog post “Vagrant: Intro”, I’ve given a short introduction to Vagrant and shown an example how it could be used. (If you haven’t read that one, you should check it out.) In this post I’ll show you how I’ve set up my personal, on-demand, Linux development environment.
By the end of this guide, you’ll have Ubuntu VM with Git, Python with Pip, and Ruby with RVM.
Setting up personal development environment involves the following elements:
- Vagrant – spawns and prepares Linux virtual machine
- Chef – handles most of VM provisioning
- Personal dotfiles – repository with desired custom settings
So let’s get started.
Let’s initialize a new vagrant project:
1 2 3 4
If you’re using RVM to manage Ruby, create the .rvmrc:
I’m also using the vagrant-cachier plugin to speed up the box provisioning. If you didn’t use vagrant-cachier till now, you’ll need to install it:
Let’s add some basic settings to
1 2 3 4 5 6 7 8 9 10
I’ve decided to go with Ubuntu Precise, but you can use whatever image you like. The cachier plugin is set to auto-detect needed caching buckets (e.g. Apt, Chef, RVM, etc.) and to use machine scope to prevent potential problems when multiple VM’s are used.
At this point you can start up the virtual box and ssh into it:
If you see the warning about mismatching guest additions, it’s probably safe just to read the warning and then ignore it in the future.
If you are using git, you probably want to create the
.gitignore file with the
Provisioning the VM
Now that some basic settings are in place, it’s time to use Chef to provision the VM.
So let’s first install Librarian-Chef. Create a file called
Gemfile with the
1 2 3
bundle install. If you do not have Bundler installed, install it by
gem install bundler.
Like Bundler and
Gemfile, Librarian-Chef uses
Cheffile, so let’s create it
with the desired cookbooks:
1 2 3 4 5 6 7 8 9
You can see I’ve decided to install Apt, Git, Python (comes with Pip) and RVM
for Ruby. So let’s download those cookbooks:
If you are using Git run:
(echo cookbooks/ && echo tmp/) >> .gitignore
Finally, modify the
Vagratfile so it has the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Here I’m specifying Chef recipes that will be used, with custom setting for RVM.
Now once again start the VM and ssh inside:
Note: you can safely ignore the warning “stdin: is not a tty”, if you get it while starting the VM.
The VM should now have Git, Python with Pip, and Ruby with RVM properly installed. Apt should also be up to date.
You can confirm this by running:
1 2 3 4 5
To suspend the VM, run
If you have questions/suggestions/comments, or just want to chat, send me an email.
That’s all for this post. If you wont to see an example how to use Vagrant to experiment and explore other software, take a look at Using Thoughtworks’ Go (Continuous Delivery) With Vagrant.
By the time you read this, repo could be ahead of this guide↩