How to go about installing and testing the PostgreSQL gem using Ruby Version Manager, Ruby 1.9.2., Mac OS X 10.5.8 and Xcode 3.1.1.

Check the PostgreSQL installation (version and location).

$ psql --version
psql (PostgreSQL) 8.4.4
contains support for command-line editing

$ which psql
/usr/local/pgsql/bin/psql

Change to use Ruby 1.9.2.

$ rvm use 1.9.2-head
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29034) [i386-darwin9.8.0]

Add rvm_archflags to ~/.rvmrc.

export rvm_archflags="-arch x86_64"

Make sure that you source the file again.

$ . ~/.rvmrc
$ env | grep rvm_archflags
rvm_archflags=-arch x86_64

Make sure that you have an up to date version of Xcode installed.

the xcode version

The Mac OS X version.

the mac os x version

Install the postgreSQL gem (passing in the location of your pg_config).

$ gem install pg -- --with-pg-config=/usr/local/pgsql/bin/pg_config
Building native extensions.  This could take a while...
Successfully installed pg-0.9.0
1 gem installed
Installing ri documentation for pg-0.9.0...
Installing RDoc documentation for pg-0.9.0...

Check that the gem works.

$ irb
ruby-1.9.2-head > require 'pg'
 => true 
ruby-1.9.2-head > p = PGconn.open(:dbname => 'hgilmour', :port => 5432)
 => #<PGconn:0x705364> 
ruby-1.9.2-head > res = p.exec('SELECT 1 as a')
 => #<PGresult:0x702268> 
ruby-1.9.2-head > res.each { | r |  puts r }
{"a"=>"1"}
 => #<PGresult:0x702268> 
ruby-1.9.2-head > res.each { | r |  puts r['a'] }
1
 => #<PGresult:0x702268> 
ruby-1.9.2-head > res = p.exec('SELECT d.datname as "Name" 
ruby-1.9.2-head'>  FROM pg_catalog.pg_database d')
 => #<PGresult:0x1dab00> 
ruby-1.9.2-head > res.each { | r |  puts r }
{"Name"=>"template1"}
{"Name"=>"template0"}
{"Name"=>"postgres"}
{"Name"=>"hgilmour"}
 => #<PGresult:0x1dab00> 
Filed under: languages, tools

comments

There are no comments.