Nick Vanderbilt
Nick Vanderbilt

Reputation: 38390

How to install gem pg on snow leopard

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.

Upvotes: 2

Views: 1704

Answers (3)

michaeldwp
michaeldwp

Reputation: 431

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 be sure to double-check your architecture, otherwise it probably won't work. ;)

Upvotes: 9

Toby Hede
Toby Hede

Reputation: 37123

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.

Upvotes: 0

Azeem.Butt
Azeem.Butt

Reputation: 5861

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

Upvotes: 1

Related Questions