使用postgres.app在rvm下需要pg的错误

我在OS X上使用Postgres.app (10.8.3)。 我修改了我的PATH以便应用程序的bin文件夹优先于所有其他文件夹。

 Rammy:~ phrogz$ which pg_config /Applications/Postgres.app/Contents/MacOS/bin/pg_config 

我安装了rvm并且可以安装pg gem而不会出错,但是当我要求它时,我收到一个错误:

 Rammy:~ phrogz$ gem -v 1.8.25 Rammy:~ phrogz$ gem install pg Fetching: pg-0.15.1.gem (100%) Building native extensions. This could take a while... Successfully installed pg-0.15.1 1 gem installed Rammy:~ phrogz$ ruby -v -e "require 'pg'" ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0] /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': dlopen(/Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: @executable_path/../lib/libssl.1.0.0.dylib (LoadError) Referenced from: /Applications/Postgres.app/Contents/MacOS/lib/libpq.dylib Reason: image not found - /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg.rb:4:in `' from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require' from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require' from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' from -e:1:in `' 

我需要做什么才能正确安装pg gem?

这对我有用:

 sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config 

只需仔细检查/Applications/Postgres93.app ..路径是否存在。

编辑 :尽管这个答案目前的票数多于接受的答案,但是接受的答案更简单,更清晰。


在安装pg gem时从路径中删除Postgres.app二进制文件,而是使用OS X中内置的postgres安装来配置gem。 稍后pg库仍将正确连接到Postgres.app服务器。

 Rammy:~ phrogz$ gem uninstall pg Successfully uninstalled pg-0.15.1 # Modify PATH to remove /Applications/Postgres.app/Contents/MacOS/bin Rammy:~ phrogz$ gem install pg Fetching: pg-0.15.1.gem (100%) Building native extensions. This could take a while... Successfully installed pg-0.15.1 1 gem installed Rammy:~ phrogz$ ruby -v -e "require 'pg'" ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0] 

我找到了一个适合我的解决方案,并且需要最少的黑客/配置。 您只需要执行一次,它将适用于每个捆绑安装。 将以下内容添加到.bash_profile,.bash_rc或等效内容中:

 export DYLD_FALLBACK_LIBRARY_PATH=/Applications/Postgres.app/Contents/MacOS/lib:$DYLD_LIBRARY_PATH 

(假设您在默认位置安装了Postgres.app)。 然后重新启动终端会话,然后重试。

直接导出到DYLD_LIBRARY_PATH可能会导致其他依赖它的应用程序出现严重问题,但使用回退路径可以避免这些问题。

也可以看看:

编辑 :当您尝试运行psql时,似乎设置DYLD_FALLBACK_LIBRARY_PATH会导致错误。 要解决此问题,您可以将以下两行添加到.bash_profile:

 alias psql="(. ~/.bash_profile; unset DYLD_FALLBACK_LIBRARY_PATH; psql)"; 

这假设您正在使用bash并且.bash_profile位于您的主目录中。 如果不是这种情况(或者如果您使用.bashrc或其他环境设置而不是.bash_profile),请将命令的~/.bash_profile部分更改为环境设置脚本的路径。

别名命令基本上启动一个子shell,它不会影响您当前的bash环境。 因此,当它取消设置DYLD_FALLBACK_LIBRARY_PATH变量时,它只是暂时的。 退出psql后,将再次设置环境变量,以便rails正常运行。

问题在于将gem链接到Postgres.app。 如果您将其链接到osx附带的postgres版本

这是一个小脚本:

  • 如果将rvm与项目gemsets一起使用: 更改为您的项目
  • 运行以下命令:

     gem uninstall pg PATH=${PATH/'Postgres.app'/'WRONGFOLDER.app'} gem install pg PATH=${PATH/'WRONGFOLDER.app'/'Postgres.app'} 
  • 现在应该没事了