Skip to content

Instantly share code, notes, and snippets.

@caike
Last active December 11, 2015 11:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/4591100 to your computer and use it in GitHub Desktop.
Save caike/4591100 to your computer and use it in GitHub Desktop.

Using vagrant

Install

  • Install VirtualBox
  • Install vagrant (use the OS installer instead of gem)

Setup

  • vagrant box add <box_name> <box_url>

  • vagrant init <box_name>

  • vagrant up

    • sometimes this command results in hanging at '[default] Waiting for VM to boot. This can take a few minutes.'. If this happens, then vagrant gem install vagrant-vbguest and vagrant vbguest --force, and try vagrant up again.
  • Install vim and git sudo apt-get install vim git-core

Installing Ruby

You can choose to install it from source. However, I find it better to install it via apt using HelloBit's repository. As of this writing, the Ruby version available there is 1.9.3p374.

  • Add the GPG public key:

  • wget -q -O - http://apt.hellobits.com/hellobits.key | sudo apt-key add -

  • Add the repository source:

  • echo 'deb http://apt.hellobits.com/ precise main' | sudo tee /etc/apt/sources.list.d/hellobits.list

  • Update package list and install Ruby:

  • sudo apt-get update

  • sudo apt-get install ruby-stable

  • Update Rubygems:

  • sudo gem update --system

Installing PostgreSQL 9.2

First, make sure the locale is set to 'en_US.UTF-8'. The locale command should list something like:

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

If not, then do these:

  • Edit the locale file(s) in /var/lib/locales/supported.d/, and remove all unneeded locales (one locale per line)
  • Edit /etc/default/locale to look like:

LANG="en_US"
LC_ALL="en_US.UTF-8"
LANGUAGE="en_US:en"

  • Delete all generated locale data: sudo rm -rfv /usr/lib/locale/*
  • Re-generate new locales: sudo locale-gen
  • Logout and reboot your machine to make your changes take effect: vagrant reload.
  • Run locale again to make sure everything is properly set.

from LinuxQuestions

  • sudo apt-get install python-software-properties (installs add-apt-repository)
  • sudo add-apt-repository ppa:pitti/postgresql (adds launchpad repo w/ postgresql 9.2)
  • sudo apt-get update

from https://launchpad.net/~pitti/+archive/postgresql

  • sudo apt-get install postgresql-9.2 postgresql-server-dev-9.2

more debugging tips at http://siddhi.blogspot.com/2011/08/setting-up-postgres-on-ubuntu-1004.html

For my development environment, I like to configure postgresql (or any other database) to not ask for password on login. This can be done by editing your pg_hba.conf file, which should be under /etc/postgresql/9.2/main/. All the way to the bottom of this file, change the authentication method for local connections to "trust". Basically, change this

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

to this

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

Then, restart your postgresql server by sudo /etc/init.d/postgresql restart.

Now, a couple of last things:

  • sudo su - postgres and createuser -s -d vagrant
  • back to the vagrant user, createdb
  • run psql and you should see the database sql prompt.

Final Tweaks

  • sudo apt-get install g++ so that we can compile therubyracer.
  • bundle
@willian
Copy link

willian commented Jan 30, 2013

Nice Gist, Dude!
I like to use a different VM for my DataBase layer, even in development, so that way I can work in a environment similar to production.

On /etc/postgresql/9.2/main/pg_hba.conf add this line at the bottom:

host    all             all             0.0.0.0/0            trust

10.10.10.* is my local network on VM. 10.10.10.2 is my Application VM and 10.10.10.3 is my DB VM.

On /etc/postgresql/9.2/main/postgresql.conf change this line:

#listen_addresses = 'localhost'          # what IP address(es) to listen on;

To this:

listen_addresses = '*'                  # what IP address(es) to listen on;

Now my PostgresSQL allows externa connections.

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