1

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
Ewan Delanoy
  • 1,276
  • 2
  • 13
  • 31
  • RVM and Ruby are not properly installed if `which ruby` returns the system version of Ruby at `/usr/bin/ruby`. What does `ruby -v` return in your console? I'm guessing it does not return `2.5.3`. Also, what is the output of `which gem`? It should be a shell function loaded by RVM, not `/usr/bin/gem`. – anothermh Dec 13 '18 at 23:45
  • I would recommend `rm -rf ~/.rvm` and then reinstall RVM, Ruby, and pg based on the update you provided. – anothermh Dec 14 '18 at 05:38
  • @anothermh Thx for your feedback. I updated the OP to include answers to your questions. Do you know any link which explains in detail how to "properly install" RVM and Ruby ? As far as I can remember, I used a mix of pre-installed stuff with a few downloads – Ewan Delanoy Dec 14 '18 at 05:40
  • Remove RVM and Ruby with `rm -rf ~/.rvm`; install RVM with `\curl -sSL https://get.rvm.io | bash -s stable`; restart your shell; install Ruby with `rvm install 2.5.3`; install PostgreSQL with `brew install postgresql`; install pg with `gem install pg`. – anothermh Dec 14 '18 at 05:41

0 Answers0