gem install pg fails on OSX 10.9 [duplicate] - ruby-on-rails

This question already has answers here:
Rails: Installing PG gem on OS X - failure to build native extension
(15 answers)
Closed 7 years ago.
when running bundle install (or gem install pg) i get the following error i have already tried fixing the xcode command line tools
/Users/josh/.rvm/rubies/ruby-2.0.0-p353/bin/ruby 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.
Ruby 2.0.0
Rails 4.0.2
OSX 10.9.1

I just had this same problem today and this answer solved it for me.
https://stackoverflow.com/a/19620569/91970
Hope that helps.
Summary
brew update
brew install postgresql
bundle install

For reference, the code #marcamillion is linking to:
brew update
brew install postgresql
bundle install

I had the same problem .. I've modified Gemfile.lock and replaced pg (0.17.1) with pg(0.18.1) only.
Download PostgreSQL 9.4 and installed in system
use following command to install pg now
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

Related

Unable to install Rails due to libxml2 not detected properly

I'm trying to install Rails on my Mac (Yosemite). I've gone through several SO questions, reinstalling libxml2 with Homebrew, and with RVM, and updating Ruby, etc. and nothing has worked so far. My libxml2 version is 2.9.2.
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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.
What should I try next?
You have issues with nokogiri building.
Try the following steps. This should work for Yosemite:
brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install

Broken Rails setup / pg gem

UGH... I broke my (formerly functioning) Rails setup - under OS X Yosemite. I did so using Homebrew to update my version of Git. After getting Git where I want it, running 'rails c' gives these errors:
/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg.rb:4:in `require': dlopen(/Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libpq.5.6.dylib (LoadError)
Referenced from: /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Reason: image not found - /Users/grogers/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/pg-0.16.0/lib/pg_ext.bundle
Seeing the reference to pg_ext, I tried to verify pieces of my postgresql installation. If I try 'gem install pg' or try to update the gem with bundler, I get this:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/grogers/.rbenv/versions/2.0.0-p353/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** 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.
I'm probably making my problem worse, but I went back and redid a 'brew install postgres' but still get the same error.
Any help appreciated. Thank you!
Did you also upgrade Postgresql via Homebrew? If not, what version of Postgres are you running, and how do you install it?
If you did upgrade your Postgres you'll need to rebuild the native bindings for the pg gem: gem uninstall pg && gem install pg.

Cannot install the gem pg -v '0.15.1'

I have tried installing the packet libpq-dev, and installing postgresql, but bundle install still fails due to gem pg. This is the error I get:
$ gem install pg -v '0.15.1'
Building native extensions. This could take a while...
/.rvm/rubies/ruby-1.9.3-
p484/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:73: warning: Insecure
world writable dir /usr/local in PATH, mode 040777
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/.rvm/rubies/ruby-1.9.3-p484/bin/ruby 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.
What is a proper way to clean up the mess?
If you are on Mac, install Homebrew and then install Postgres using the command
brew install postgresql
Or you can download and install Postgres from here depending on which OS you are using.
There isn't any "mess" - it's a standard issue where your system does not have the required libraries to install the gem
Library
As mentioned in the comments, you first need to install PGSQL, which will create the required library files to help the gem install, after that you can use some path references to help the gem install:
gem install pg -- --with-pg-dir="C:/Program Files/installer

"bundle update" failed to install pg (0.14.1) with native extensions

I ran bundle update (so that I can install rails), but got this error:
$ bundle update
..... < other stuff ....>
Installing pg (0.14.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p374/bin/ruby 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.
I'm new to Ruby and all this, could anyone tell me what is wrong here?
This is on OSX
Make sure ton install postgres first. I suggest you do so via homebrew, the Mac package manager.
brew install postgresql
Here is one of the many tutorials on how-to install postgres on a Mac.
EDIT
Looks like the gem can't find your postgres config, here's an answer similar to your problem:
https://stackoverflow.com/a/9669523/277370

Error while installing cucumber (involving gherkin)

I'm trying to set up cucumber for rails. I included this in my Gemfile and ran bundle install.
gem 'cucumber-rails'
gem 'database_cleaner'
I got this error. What should I do?
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
/Users/[my_user_name]/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for main() in -lc... *** 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.
This question is a bit old, but as I just had a similar problem on my machine I will document my solution here.
The problem seems to be related to OS X Lion, GCC, clang etc. (see https://github.com/carlhuda/bundler/issues/1590 and https://github.com/carlhuda/bundler/issues/1600). As how ruby was compiled seems to be the problem I decided to re-install (and also upgrade) ruby.
Here is what solved this issue for me:
I use the Command Line Tools for Xcode package.
Furthermore the current version of rbenv and ruby-build (both installed via homebrew)
rbenv install 1.9.3-p125 failed (see https://github.com/sstephenson/ruby-build/issues/129 and https://github.com/sstephenson/ruby-build/issues/130)
remove the require_gcc line for 1.9.3-p125 (if installed with homebrew you find the file under /usr/local/Cellar/ruby-build/20120216/share/ruby-build/1.9.3-p125)
finally successfully install 1.9.3-p125 with env CC=/usr/bin/gcc rbenv install 1.9.3-p125
Complicated but I can now install gems with natiive extensions.
Hope this helps.
Update: btw. It is possible to keep using ruby-1.9.2-p290, all you have to do is re-install it.
First "uninstall" the old ruby-1.9.2-p290: rm -rf .rbenv/versions/1.9.2-p290
Next remove the require_gcc line for 1.9.2-p290
Finally install with env CC=/usr/bin/gcc rbenv install 1.9.2-p290

Resources