Skip to content

Instantly share code, notes, and snippets.


heycarsten/ Secret

Last active Dec 15, 2015
What would you like to do?
Ideal development VM build.

How I manually build a Vagrant VM

Start from Vagrant supplied VMware Fusion Ubuntu base box:

From there I would:

Make a temporary directory to compile the shit out of things:

mkdir ~/src

Update shit:

sudo apt-get update
sudo apt-get upgrade

Then set the locale:

sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8

Then set the timezone to UTC:

sudo dpkg-reconfigure tzdata

Then install Postgres 9.3:

First, I update the shit according to this article:


sudo vim /etc/apt/sources.list.d/pgdg.list

And add the following line to that file:

deb precise-pgdg main

If you're not using precise, then run lsb_release -c to get the codename of the release you are running and substitute accordingly.

Next add the Postgres repository key:

wget --quiet -O - | sudo apt-key add -

Now we can install Postgres:

sudo apt-get update
sudo apt-get install postgresql-9.3 libpq-dev postgresql-contrib-9.3

After that I run pg_tune:

cd ~/src
tar xzf pgtune-0.9.3.tar.gz
sudo ./pgtune-0.9.3/pgtune -i /etc/postgresql/9.3/main/postgresql.conf -o /etc/postgresql/9.3/main/postgresql.conf.pgtune
sudo mv /etc/postgresql/9.3/main/postgresql.conf /etc/postgresql/9.3/main/postgresql.conf.original
sudo mv /etc/postgresql/9.3/main/postgresql.conf.pgtune /etc/postgresql/9.3/main/postgresql.conf
sudo chown postgres:postgres /etc/postgresql/9.3/main/postgresql.conf

Then create a PG superuser for the login user (vagrant):

sudo su - postgres
createuser -s vagrant

Then install Redis:

cd ~/src
tar xzf redis-2.8.4.tar.gz
cd redis-2.8.4
sudo make install
sudo cp redis.conf /etc/redis.conf
sudo useradd -r redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
# Then I change the data directory to /var/lib/redis and I set
# it to use syslog for logging:
sudo vim /etc/redis.conf

Next I make a shitty Upstart script for Redis:

I add the following to a file at /etc/init/redis.conf

description "Redis"
start on runlevel [23]
stop on shutdown
exec sudo -u redis /usr/local/bin/redis-server /etc/redis.conf

Next I install Nginx with the upload module so we can do fancy XHR file uploads and not send massive BLOBs to Rails:

sudo apt-get install libpcre3-dev # For regex matching, might already be in base box?
cd ~/src
tar xzf nginx-1.4.4.tar.gz
cd nginx-1.4.4
./configure --with-http_ssl_module --with-http_gzip_static_module
sudo make install
sudo useradd -r nginx
sudo mkdir /var/log/nginx
sudo chown nginx:nginx /var/log/nginx

Now I use this as my base Nginx config which I place at /etc/nginx.conf:

worker_processes 1;
user nginx nginx;
pid /var/run/;

events {
  worker_connections 1024;
  use epoll;

http {
  client_max_body_size 1g;

  include /usr/local/nginx/conf/mime.types;

  access_log /dev/null;
  error_log /dev/null;

  upstream rack_app {
    server fail_timeout=0;

  server {
    root /vagrant/public;

    try_files $uri/index.html $uri.html $uri @upstream_app;

    location @upstream_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://rack_app;

Next I create another Upstart for Nginx at /etc/init/nginx.conf:

description "Nginx"
start on runlevel [2]
stop on runlevel [016]
console owner
exec /usr/local/nginx/sbin/nginx -c /etc/nginx.conf -g "daemon off;"

At this time I will often install Imagemagick:

sudo apt-get install imagemagick

Now is when I usually install any project specific dependencies.

Next I install RVM:

curl -L | bash -s stable

Once it installs it shits out a bunch of crap in ~/, so I remove the zsh configs that it adds and (as it recommends) I add the following line to the top of ~/.bash_profile:

source ~/.profile

At this point I usually log out and back in, then:

rvm autolibs enable
rvm requirements

This will install all the required packages using apt, sweeeeeet!

After that I install the Rubies I want:

rvm install 1.9.3
rvm install 2.1.0

Then I set a default:

rvm use 2.1.0 --default

At this point, I restart the box, and then it's ready to start using for development.


This comment has been minimized.

Copy link

@mmun mmun commented Mar 16, 2013

I printed this out and framed it on my wall.


This comment has been minimized.

Copy link
Owner Author

@heycarsten heycarsten commented Mar 20, 2013

@mmun ❤️ ❤️ ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment