4

I just installed PostgreSQL and the pg gem for running Rails on Heroku. I'm running

$ rake -T

But it's aborting for reason related to "libpq.5.dylib"

rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.13.2/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib
Referenced from: /Library/Ruby/Gems/1.8/gems/pg-0.13.2/lib/pg_ext.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/pg-0.13.2/lib/pg_ext.bundle

What gives?

How can load the libpq.5.dylib library?

jwilsco
  • 388
  • 2
  • 8

2 Answers2

4

I am on a Mac. Here is what I did to get it working.

cd /Library/Ruby/Gems/1.8/gems/pg-0.13.2/lib/
otool -L pg_ext.bundle

libpq.5.dylib (compatibility version 5.0.0, current version 5.4.0)

Notice that libpq.5.dylib doesn't use an absolute path like the other libs in pg_ext.bundle. The system can't find it. You need to change where it looks for libpq.5.dylib.

install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.1/lib/libpq.5.dylib pg_ext.bundle

Note: Use the absolute path that applies to your system. I used what it was for my system.

Now run:

otool -L pg_ext.bundle

Notice what libpq.5.dylib points to now:

/Library/PostgreSQL/9.1/lib/libpq.5.dylib (compatibility version 5.0.0, current version 5.4.0)

The pg gem should be happy now.

Jared Brown
  • 1,949
  • 4
  • 20
  • 28
  • Here's another approach that may work if you're running into this problem: http://stackoverflow.com/questions/24627465/ruby-pg-gem-linking-to-wrong-copy-of-libpq-5-dylib-on-osx – Jan Hettich Jul 08 '14 at 23:12
2

From the discussion here it seems like compiling 64-bit Ruby's pg against 32-bit Postgresql is the source of the problem. So the only way to solve it is to install 64-bit Postgresql and then reinstall pg.

This post explains the issue in detail.

meandre
  • 2,141
  • 2
  • 16
  • 21