When I do gem install pg
in my Rails project, I get the error message Can't find the PostgreSQL client library (libpq), extconf.rb failed
This is the exact same problem described in this older SO question, so I got inspiration from the answers therein ; after a bit of trial and error, I saw that even though my Mac has an i386 architecture,
env ARCHFLAGS="-arch i386" gem install pg
does not work (gem install pg
fails with the same error message) ; on the other hand,
env ARCHFLAGS="-arch x86_64" gem install pg
executes without any errors ; but then, rails server
fails with the following error message :
/Users/ewandelanoy/.rvm/gems/ruby-2.5.3/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `require':
dlopen(/Users/ewandelanoy/.rvm/gems/ruby-2.5.3/gems/therubyracer-0.12.3/lib/v8/init.bundle,0x0009): could not use '/Users/ewandelanoy/.rvm/gems/ruby-2.5.3/gems/therubyracer-0.12.3/lib/v8/init.bundle' because it does not contain required architecture x86_64h -
/Users/ewandelanoy/.rvm/gems/ruby-2.5.3/gems/therubyracer-0.12.3/lib/v8/init.bundle
(LoadError)
If it matters, here is some extra info :
I installed Postgres with homebrew.
$ file `which ruby`
/usr/bin/ruby: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [i386:Mach-O executable i386]
/usr/bin/ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/ruby (for architecture i386): Mach-O executable i386
$ file `which postgres`
/usr/local/bin/postgres: Mach-O 64-bit executable x86_64
In answer to a comment below :
$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
$ which gem
/Users/ewandelanoy/.rvm/rubies/ruby-2.5.3/bin/gem