1

I get the below error when I execute 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.

I don't know why I get this issue. And I execute the 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

My Gemfile is this:

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]

Edit -1

My OS is macOS Sierra

user7693832
  • 6,119
  • 19
  • 63
  • 114

2 Answers2

7

I had a similar problem and this is what worked for me:

(Note: First make sure you've got XCode and homebrew installed)

  1. brew install postgresql

  2. gem uninstall pg - this might not return anything, that's ok.

  3. Then in your app's directory, either bundle install or gem install pg

nope2023
  • 1,668
  • 1
  • 15
  • 28
0

This issue often comes up and mostly results in obsolete version of Postgres. Try

brew update 
brew install postgresql
bundle install

If you still need to use that version of Postgres you can specify the path to the 'pg_config':

gem install pg -- --with-pg-config=<path to pg_config>
Alexander Gorg
  • 1,049
  • 16
  • 32