Tag Archives: gems

Bundler Failing to Build Native Extensions

It was apparent that my 2011 MacBook Air needed a rebuild when it would sit, sometimes up to three minutes after coming back from sleep, screen lock, or restart, loading the login screen. I have worked at three different places of employment with this laptop, each place requiring a number of different processes and applications running on the machine in order for me to work effectively. It had finally become out of control and enough was enough. I wiped the machine and performed a fresh install of Mavericks.

Everything was going very smoothly until it came to install my gems for the current Rails project I am working on. Every single time I would try to bundle install gems, I would get the same error, for different gems. The one erring out below happens to be the do_postgres gem, but the error was always the same:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for main() in -lpq... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for postgres.h... yes
checking for mb/pg_wchar.h... no
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pgsql-server-dir
--without-pgsql-server-dir
--with-pgsql-server-include
--without-pgsql-server-include=${pgsql-server-dir}/include
--with-pgsql-server-lib
--without-pgsql-server-lib=${pgsql-server-dir}/
--with-pgsql-client-dir
--without-pgsql-client-dir
--with-pgsql-client-include
--without-pgsql-client-include=${pgsql-client-dir}/include
--with-pgsql-client-lib
--without-pgsql-client-lib=${pgsql-client-dir}/
--with-pqlib
--without-pqlib
Could not find PostgreSQL build environment (libraries & headers): Makefile not created

extconf failed, exit code 1

I must have Googled a hundred sites. Most answers I found suggested to install the Xcode command line tools. I did that. And did it again. And probably again, just because I’m a little insane like that. Other people suggested that it was a Postgres issue and simply uninstall Postgres, reinstall and observe the magic. There was no magic for me. Nothing.

Frustrated, I typed gem install do_postgres from the command line, not using bundler. It worked! But why? Finally my awesome husband and I sat down to figure this out.

We found an issue similar to mine here¬†and TimMoore stated “I’d bet that the problem is that Bundler itself is installed as gem under the system Ruby, rather than the one in ~/.rubies.” Bingo.

I use rbenv to manage my Ruby versions. It seemed for some reason bundler was using the system Ruby rather than what was specified by rbenv. I wish I could go back in time to verify this, but odds are, for some reason, I installed bundler before I installed rbenv. I don’t know why I would have done that, and I honestly do not remember. We updated the /usr/bin/bundler to look in /Users/jpayne/.rbenv/shims/ruby rather than /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby and that worked.

I, of course, was not going to accept that updating that file was the solution, so I uninstalled bundler, went back into my project directory (with my rbenv gemset in place) and reinstalled bundler. I then did a bundle install to try it out and was extremely pleased to discover that building the native dependencies for all gems had been successful.

My laptop is now a bit speedier because of the rebuild, and I have my project up and running again.