Vagrant, RBENV, Rails 4 and PostgreSQL headaches


Warning - Old content ahead!

This page has been marked as a legacy post. This means it's quite old (from 2014) and probably out of date. Take it with a grain of salt!

Forewarning: This post is more of a rambling and future reference to myself.

I've been working on a project in Ruby on Rails for a little while and a few days ago I made the mistake of upgrading to OS X Mavericks with the thoughts "What's the worst that could happen?" running through my mind.

Well for some reason the PG gem really doesn't like my computer anymore. Long story short I decided that I would fire up a Ubuntu development environment on Vagrant and well, it has been a difficult ride.

To keep it short. First time around I had many issues.

Vagrant was making rails take forever to download. The solution to this can be found here:

TL;DR: Add this to your vagrant file and restart it.

config.vm.provider "virtualbox" do |vb|
  vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
  vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]

Make sure you rbenv rehash after installing both Ruby and Rails.

After mucking up with Nokogiri and PG dependancies I hit a wall with folder permissions and Bundler.

I decided to start again following this guide:

This went much smoother, installing all dependences beforehand. Note that Adding a new Repository to Ubuntu didn't work without first running

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-get install python-software-properties

But besides that everything worked fine. Bundle install worked with no issues which makes me very happy!

My final issue was creating and migrating the database via rake.

PG::InvalidParameterValue: ERROR:  encoding "UTF8" does not match locale "en_US"
DETAIL:  The chosen LC_CTYPE setting requires encoding "LATIN1".

This was a real pain and seemed to be a default for PostgresSQL conflicting with Rails.

To fix I logged into psql with sudo su postgres -c psql and followed the advise posted by tokhi on Stackoverflow

Or alternatively this post:

Now it all works and hopefully this will resolve any future issues I have with rails deployments!

Spread the word

Share this article

Like this content?

Check out some of the apps that I've built!


Command-line snippet manager for power users



Third party app for iOS.



GUI for the rsync command