ruby-on-rails - 安装pg(0.18.2)时出错,Bundler无法继续

标签 ruby-on-rails postgresql

跟随 Tony Coconate 的 Rails + Ember.js (with the Ember CLI) 教程,我们正在尝试创建一个新的 Rails API。

当我们运行 rails new api -T -d postgresql 时,我们收到以下错误消息:

An error occurred while installing pg (0.18.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.2'` succeeds before bundling.

这是 Gemfile 文件的样子:

source "https://rubygems.org"

gem "rails", "4.2.1"

gem "activeadmin", github: "gregbell/active_admin" # Until it"s 1.0.0
gem "coffee-rails", "~> 4.0.0"
gem "devise"
gem "grape"
gem "grape-active_model_serializers"
gem "grape-swagger-rails"
gem "jquery-rails"
gem "pg"
gem "rack-cors", require: "rack/cors"
gem "sass-rails", "~> 4.0.3"
gem "uglifier", ">= 1.3.0"

group :development do
  gem "better_errors"
  gem "meta_request"
  gem "quiet_assets"
  gem "spring"
end

group :development, :test do
  gem "capybara"
  gem "capybara-screenshot"
  gem "database_cleaner"
  gem "factory_girl_rails"
  gem "faker"
  gem "poltergeist"
  gem "pry-nav"
  gem "pry-rails"
  gem "pry-stack_explorer"
  gem "pry-theme"
  gem "rspec-rails"
  gem "rubocop"
  gem "shoulda-matchers"
  gem "spring-commands-rspec"
end

当我们运行 bundle install 时,我们收到以下错误消息:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/user_name/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150629-73521-9m0ocx.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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/user_name/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
    --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}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/user_name/.rvm/gems/ruby-2.2.1/gems/pg-0.18.2 for inspection.
Results logged to /Users/user_name/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.2/gem_make.out
An error occurred while installing pg (0.18.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.2'` succeeds before bundling.

当我们运行 gem install pg -v '0.18.2' 时,我们也得到一个错误:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/user_name/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150629-73553-uaymt5.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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/user_name/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
    --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}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/user_name/.rvm/gems/ruby-2.2.1/gems/pg-0.18.2 for inspection.
Results logged to /Users/user_name/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.2/gem_make.out

知道哪里出了问题,最重要的是,我们该如何解决?

最佳答案

好的,所以我找到了解决问题的方法。

首先,我用自制软件安装了 pg gem,as explained here :

brew install postgres

然后,我无法启动rails server,所以我按照this solution然后跑:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

现在,一切正常。

关于ruby-on-rails - 安装pg(0.18.2)时出错,Bundler无法继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31123729/

相关文章:

ruby-on-rails - rails+rspec+capybara 测试编辑资源

ruby-on-rails - 如何从 Controller 访问嵌套的 JSON 参数?

postgresql - cakephp 3 postgres 9.4 驱动程序烘焙

python - 在 Django 应用程序中,即使迁移文件夹文件被删除,此错误也存在 'relation "blog_no_of_views“不存在”

postgresql - Postgres 没有这样的接口(interface) 'org.freedesktop.DBus.Properties'

ruby-on-rails - 如何让回形针删除文件

ruby-on-rails - 等效的 HMAC SHA-512 key

ruby-on-rails - 设计omniauth-facebook redirect_uri 不是绝对URI

postgresql - 在 Amazon RDS Postgres 上编写 PostGIS 设置脚本

postgresql - Heroku 数据库 :migrate error