views:

244

answers:

4

I need to install gem pg on snow leopard because I am running rake on rails codebase. I am not using postgres.

This is the error I am getting.

$ sudo gem install pg
Password:
Sorry, try again.
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

looked at various blogs from google search but none of them work.

A: 

Maybe you need XCode installed.

markgx
A: 

You probably need to actually build and install Postgres before you can build a Ruby adaptor for it.

Azeem.Butt
A: 

If you aren't using Postgres, you shouldn't need to install the driver - you only need the driver for the database you are using.

Toby Hede
A: 

I'm not quite sure why you're installing the pg gem if you're not using PostgreSQL, but anyway:

You may have to specify your CPU architecture. First, run the following to see which architecture you're running on:

(Note: Replace '/usr/bin/ruby' with whatever 'which ruby' returns).

$ lipo -detailed_info /usr/bin/ruby

In there, you should see something about your architecture (look for 'i386' or 'x86_64')

If that doesn't work, try the following:

$ irb
['foo'].pack('p').size

The result will be '8' if Ruby is running as 64-bit, or '4' if it's running in 32-bit.

Then, when you go to install the Postgres gem, specify the appropriate architecture:

$ sudo env ARCHFLAGS="-arch i386" gem install pg

Or,

$ sudo env ARCHFLAGS="-arch x86_64" gem install pg

If you're running Snow Leopard with a 64-bit CPU, then you're probably running the 64-bit version. But still double-check your architecture.

mikep