【问题标题】:Bundle Install fails due to problems with 'pg (>= 0) ruby` on OSX Yosemite由于 OSX Yosemite 上的 'pg (>= 0) ruby​​` 问题,Bundle Install 失败
【发布时间】:2017-01-12 19:25:58
【问题描述】:

在问题结束时更新了解决方案

我一直在兜圈子,试图解决我的 pg gem & rails 服务器的问题。我已经概述了我发现自己陷入的无限循环。您能否提供一些指导?

当我尝试启动我的 rails 服务器时,我收到以下错误消息:

Could not find gem 'pg (>= 0) ruby' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.

之后,我运行bundle install 并收到以下消息:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /var/folders/3l/gxc7bb4x0nb6b7n7039jl49r0000gn/T/bundler20170112-83505-1jpf7s0pg-0.19.0/gems/pg-0.19.0 for inspection.
Results logged to /var/folders/3l/gxc7bb4x0nb6b7n7039jl49r0000gn/T/bundler20170112-83505-1jpf7s0pg-0.19.0/gems/pg-0.19.0/ext/gem_make.out
An error occurred while installing pg (0.19.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.19.0'` succeeds before bundling.

接下来我运行 gem install pg -v '0.19.0' 并收到以下错误消息:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

然后我尝试运行 sudo gem install pg -v '0.19.0' 并收到以下错误消息:

ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/pg-0.19.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/pg-0.19.0/ext/gem_make.out

如果有帮助,我还运行了 rbenv versions,它显示:

  system
* 2.1.0 (set by /Users/{user}/.rbenv/version)

我还尝试完全卸载 postgres,然后使用本指南重新安装:https://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/

我该去哪里?

【问题讨论】:

  • 你的电脑上是否安装了 postgresql(服务器或客户端)?
  • 是的,我在此之前运行了 brew updatebrew install postgresql。我会更新帖子。
  • ARCHFLAGS='-arch x86_64' gem install pg 有区别吗?
  • 看起来不像:ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
  • 嗯,您似乎没有在 rbenv 下运行,因为它正在尝试安装在系统 ruby​​ 上,因此您可能会遇到多个问题。

标签: ruby-on-rails macos postgresql rubygems pg


【解决方案1】:

尝试安装postgresql

brew install postgresql

如果它不起作用,请更新 brew

brew update

再试一次

已编辑。

另一种解决方案是安装xcode命令行工具

xcode-select --install

【讨论】:

  • 感谢您的快速回复。在这个问题之前,我遵循了这个教程:moncefbelyamani.com/… 并且可以确认lunchy start postgres 有效。我会更新帖子。
  • 感谢更新的解决方案:xcode 命令行工具已安装。
【解决方案2】:

基本上,我最终完全卸载/重新安装了所有内容。以下是我从头开始重建的所有内容:

  1. 卸载/重新安装 PostgreSQL
  2. 更新了路径变量,使 anaconda 位于末尾
  3. 重新安装 rbenv
  4. 卸载/重新安装 Ruby 2.1.0
  5. 重新运行 gem install bundle
  6. 重新运行捆绑安装
  7. 重新运行 rake db:setup 和 rake db:migrate

然后事情就终于摆平了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-09
    • 2022-11-01
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 2015-09-24
    • 1970-01-01
    相关资源
    最近更新 更多