在Rails项目中执行gem install pg
时,收到错误消息Can't find the PostgreSQL client library (libpq), extconf.rb failed
这与this较旧的SO问题中描述的问题完全相同,因此我从其中的答案中得到了启发;经过一番尝试和错误,我发现即使我的Mac具有i386架构,
env ARCHFLAGS="-arch i386" gem install pg
不起作用(gem install pg
失败,并显示相同的错误消息);另一方面,
env ARCHFLAGS="-arch x86_64" gem install pg
执行没有任何错误;但是随后rails server
失败,并显示以下错误消息:
/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)
如果有关系,这里有一些额外的信息:
我用自制软件安装了Postgres。
$ 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
回答以下评论:
$ 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