Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

robberbaron
robberbaron
23,869 Points

Ruby on Rails: bundle fails… cannot gem install pg (not yet resolved - need help)

Hi !

While building a simple Ruby on Rails app I ran into an error with the suggested command "bundle".

Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.3.6)
Using activesupport (3.2.6)
Using builder (3.0.0)
Using activemodel (3.2.6)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.3)
Using actionpack (3.2.6)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.4)
Using actionmailer (3.2.6)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.6)
Using activeresource (3.2.6)
Using bcrypt-ruby (3.0.1)
Using coffee-script-source (1.3.3)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.7.3)
Using rdoc (3.12)
Using thor (0.15.4)
Using railties (3.2.6)
Using coffee-rails (3.2.2)
Using orm_adapter (0.4.0)
Using warden (1.2.1)
Using devise (2.1.2)
Using request_store (1.0.5)
Using draper (1.0.0)
Using factory_girl (4.1.0)
Using factory_girl_rails (4.1.0)
Using jquery-rails (2.0.2)
Using bundler (1.5.2)
Using rails (3.2.6)
Using js-routes (0.8.5)

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

    /Users/marc/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** 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/marc/.rvm/rubies/ruby-2.1.0/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
    --without-pg-config
    --with-pg_config
    --without-pg_config
/Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1120:in `block in find_header'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1119:in `find_header'
    from extconf.rb:41:in `<main>'

extconf failed, exit code 1

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

As the last lines of the output suggest I tried to do a "gem install pg" (did it with version 0.14, 0.17 and 0.17.1 all with the same results…

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

    /Users/marc/.rvm/rubies/ruby-2.1.0/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.

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/marc/.rvm/rubies/ruby-2.1.0/bin/ruby
    --with-pg
    --without-pg
    --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
/Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:541:in `try_link0'
    from /Users/marc/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:556:in `try_link'
    from extconf.rb:39:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/marc/.rvm/gems/ruby-2.1.0/gems/pg-0.17.1 for inspection.
Results logged to /Users/marc/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/pg-0.17.1/gem_make.out

As the above result said that I would have to install Dev Tools first… I checked them in Xcode with the result that they are installed. Maybe make wasn't linked so I did a soft link from the developer tools make to /usr/bin/make

did not help either…

mkmf.log reports:

find_executable: checking for pg_config... -------------------- yes

--------------------

"/usr/bin/clang -o conftest -I/Users/marc/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/x86_64-darwin12.0 -I/Users/marc/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/ruby/backward -I/Users/marc/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0 -I. -I/usr/local/Cellar/postgresql/9.3.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -I/Users/mpapis/.sm/pkg/active/include -fPIC -mmacosx-version-min=10.6 -pipe conftest.c  -L. -L/Users/marc/.rvm/rubies/ruby-2.1.0/lib -L/usr/local/Cellar/postgresql/9.3.2/lib -L. -L/Users/mpapis/.sm/pkg/active/lib -L/usr/lib -fPIC -Bstatic -fstack-protector   -arch x86_64   -lruby-static -framework CoreFoundation  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

/Users/marc/.rvm/gems/ruby-2.1.0/gems/pg-0.17.0/ext/mkmf.log (END) 

Any ideas?

4 Answers

Nick Fuller
Nick Fuller
9,027 Points

Hi Marc,

Welcome to the world of open source! :)

When I'm presented with these issues, I tend to pick a line and throw it out to the "Google Gods". In this case, I grabbed the following line because that is where I saw the first error.

checking for libpq-fe.h... *** extconf.rb failed ***

I found a link to stackoverflow with someone else having the same issue. As you grow and learn more and more, you will fall in love with StackOverflow! I have learned so much from there.

http://stackoverflow.com/questions/9668753/rails-3-cant-install-pg-gem

Now, I cannot guarantee that this is the solution, so please try it at your own discretion.

One quick question, are you using Homebrew? (http://brew.sh/)

If not, I cannot stress the importance of using it!

Let us know how it goes!

robberbaron
robberbaron
23,869 Points

Hi Nicholas,

thank you for your elaborate answer.

I all stack overflow articles that there are on stackoverflow regarding this topic and also tried this one. The article that you suggested really seamed a good idea to me - thanks for the suggestion. Unfortunately also this one did not help. Same error again.

Yes I'm using brew. I used to use brew in parallel with ports which was not really the best idea :-) so I was fighting error messages all day within brew haha… :-) Now brew works as it should…

Nevertheless the error remains…

Will continue the lecture without bundle hoping that I'll get through without having to use it again… :-)

Thanks again Marc

This is an old thread but this may help others like me who ran into the same problem.

Running "brew install libpqxx" fixed it for me

Rod