【问题标题】:Why isn't bundle install allowing for the pg gem to fully install?为什么捆绑安装不允许完全安装 pg gem?
【发布时间】:2011-08-29 10:17:02
【问题描述】:

我已经如图所示安装了 pg gem,但是...

Building native extensions.  This could take a while...
    Successfully installed pg-0.11.0
    ERROR:  Could not find a valid gem '—' (>= 0) in any repository
    ERROR:  Could not find a valid gem '–with-pg-config=/usr/local/pg/bin/pg_config' (>= 0) in any repository
    1 gem installed
    Installing ri documentation for pg-0.11.0...
    Installing RDoc documentation for pg-0.11.0...

当我捆绑安装时发生了一些奇怪的事情,它不会完全安装 pg gem:

Fetching source index for http://rubygems.org/
Using rake (0.9.2) 
Using abstract (1.0.0) 
Using activesupport (3.0.10) 
Using builder (2.1.2) 
Using i18n (0.5.0) 
Using activemodel (3.0.10) 
Using erubis (2.6.6) 
Using rack (1.2.3) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.29) 
Using actionpack (3.0.10) 
Using mime-types (1.16) 
Using polyglot (0.3.2) 
Using treetop (1.4.10) 
Using mail (2.2.19) 
Using actionmailer (3.0.10) 
Using arel (2.0.10) 
Using activerecord (3.0.10) 
Using activeresource (3.0.10) 
Using annotate (2.4.0) 
Using bundler (1.0.18) 
Using diff-lcs (1.1.2) 
Using factory_girl (1.3.3) 
Using rdoc (3.9.3) 
Using thor (0.14.6) 
Using railties (3.0.10) 
Using rails (3.0.10) 
Using factory_girl_rails (1.0) 
Using faker (0.3.1) 
Using gravatar_image_tag (1.0.0.pre2) 
Using nokogiri (1.5.0) 
Installing pg (0.11.0) with native extensions /Users/******/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

然后我得到的行告诉我我可能缺少必要的库或标题:

   *** 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=/Users/TonyNg/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
extconf.rb:24:in ``': No such file or directory - /users/****/

这是我的 gem 文件:

  source 'http://rubygems.org'

gem 'rails', '3.0.10'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate', '3.0.pre2'



group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '2.4.0'
  gem 'faker', '0.3.1'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'spork', '0.9.0.rc8'
  gem 'factory_girl_rails', '1.0'
end

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

我该如何解决这个问题?提前致谢。

编辑 答:诀窍是在 正确 路径下安装 pg gem 到 pg_config,而在它没有完全安装之前。我为我在上一条评论下写下的路径运行了 'gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config '。我只需要找到我的 pg_config 文件并在该文件下运行 gem install。

【问题讨论】:

  • 您是否安装了 PostgreSQL 及其库? mkmf.log 有什么要说的?
  • @mu 太短,我已经搜索了我的 mac,但找不到此特定事件的“mkmf.log”。我一定没有安装该库,因为我得到:'正在检查 pg_config... 否 没有 pg_config... 无论如何都在尝试。如果构建失败,请再试一次 --with-pg-config=/path/to/pg_config 检查 libpq-fe.h... no'。我确实安装了 PostgreSQL84。但是当我捆绑安装库时,这些是我遇到的错误。
  • 如果你在 Lion 上你需要指定架构,Google lion pg gem x86_64 archflag env
  • @mu 太短。是的,我知道,它在 /opt/local/lib/postgresql84/bin/pg_config 下,我刚刚打开它。我想你在谈论 exec 文件?我还有一个 pg_config 文件夹和 .h 文件。我不在 Lion 上,但我尝试了 'sudo env ARCHFLAGS="-arch x86_64" gem install pg',但也没有用。
  • @mu 太短。我得到了它!抱歉打扰了,我对此很陌生。诀窍是在 pg_config 的 correct 路径下安装 pg gem,而在它没有完全安装之前。我为我在上一条评论下写下的路径运行了 'gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config '。非常感谢!

标签: ruby-on-rails postgresql installation gem bundler


【解决方案1】:

之前需要安装libpq-dev

【讨论】:

  • 在 OSX 上安装它的一个好方法是从 enterprisedb 站点下载 PG。
【解决方案2】:

诀窍是在 pg_config 的正确路径下安装 pg gem,而在它没有完全安装之前。 在找到 pg_config exec 文件后,我运行了 gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config。我只需要找到我的 pg_config 文件并在该路径下运行 gem install。

【讨论】:

    【解决方案3】:

    ubuntu 18.04,需要运行sudo apt install libpq-dev

    【讨论】:

    • 真棒@FiftiN
    【解决方案4】:

    对于 Windows 和 pg gem 的最新版本 0.13.0,您应该可以使用以下方式安装它:

    subst X: "C:\Program Files\PostgreSQL\9.0"
    gem install pg -- --with-pg=X:
    subst X: /D
    

    然后就可以成功运行bundle install,在输出中看到如下一行:

    Using pg (0.13.0)
    

    而不是错误。

    [这与this对相关问题Can't install pg gem on Windows的回答相同。]

    【讨论】:

      【解决方案5】:

      在 ubuntu 18.04 上运行以下命令

      sudo apt update
      sudo apt install libpq-dev
      

      【讨论】:

        【解决方案6】:

        对于 iOS :

        brew install libpq
        

        参考:https://formulae.brew.sh/formula/libpq

        【讨论】:

        • iOS?我不认为 Homebrew 在 iOS 上可用,也不是可以运行它的 shell。你是说 macOS 吗?
        猜你喜欢
        • 1970-01-01
        • 2014-02-01
        • 2018-10-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-14
        • 1970-01-01
        • 2013-09-02
        • 1970-01-01
        相关资源
        最近更新 更多