关于rails上的ruby:在捆绑之前确保`gem install pg -v’0.18.4’成功

Make sure that `gem install pg -v '0.18.4'` succeeds before bundling

执行bundle update时出现以下错误:

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/Users/jack/.rvm/gems/ruby-2.3.3/extensions/x86_64-darwin-16/2.3.0/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/jack/.rvm/gems/ruby-2.3.3/gems/pg-0.18.4 for inspection.
Results logged to
/Users/jack/.rvm/gems/ruby-2.3.3/extensions/x86_64-darwin-16/2.3.0/pg-0.18.4/gem_make.out

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

我不知道为什么我会遇到这个问题。 然后我执行gem install pg -v '0.18.4'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Users/jack/.rvm/gems/ruby-2.3.3/extensions/x86_64-darwin-16/2.3.0/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/jack/.rvm/gems/ruby-2.3.3/gems/pg-0.18.4 for inspection.
Results logged to /Users/jack/.rvm/gems/ruby-2.3.3/extensions/x86_64-darwin-16/2.3.0/pg-0.18.4/gem_make.out

我的Gemfile是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
source 'https://gems.ruby-china.org'
gem 'rails', '5.0.0.1'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.4.1'

group :development, :test do
gem 'sqlite3', '1.3.11'
gem 'byebug', '9.0.0', platform: :mri
end

group :development do
  gem 'web-console', '3.1.1'
  gem 'listen', '3.0.8'
  gem 'spring', '1.7.2'
  gem 'spring-watcher-listen', '2.0.0'

end
group :production do gem 'pg', '0.18.4'
end
    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

编辑-1

我的操作系统是macOS Sierra


我遇到了类似的问题,这对我有用:

(注意:首先确保你已经安装了XCode和自制软件)

  • brew install postgresql

  • gem uninstall pg - 这可能不会返回任何内容,这没关系。

  • 然后在你的应用程序目录中,bundle installgem install pg


  • 这个问题经常出现,并且主要导致Postgres的过时版本。
    尝试

    1
    2
    3
    brew update
    brew install postgresql
    bundle install

    如果您仍然需要使用该版本的Postgres,您可以指定'pg_config'的路径:

    1
    gem install pg -- --with-pg-config=<path to pg_config>