Archive for the ‘bundler’ category

How to solve “Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension”

March 2nd, 2012

With the joys of ruby 1.8.7 on OS X 10.7.3, i had to include a manual build step to get get mysql to build. This was the error i was seeing:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… 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.

The solution was to manually install the gem that had been stored in the temporary directory:

cd~/.bundler/tmp/85326/gems/mysql-2.8.1/

sudo gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config

Once done, bundle install worked and used the installed gem

Ensuring postgres gem is installed on heroku when using Rails 3.1

January 7th, 2012

It turns out that Rails 3.1 doesn’t come with a database adapter. So, when deploying to heroku, the app will blow up unless you add the require postgres gem to your gem file:

group :production do
gem “pg”
end

group :production do

gem “pg”

end

This resolves the heroku error

/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection’: Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

Ensuring that Heroku does not install gems within the Bundler :development group

January 7th, 2012

Tonight, i ran into an issue with Heroku, where is was failing when installing a gem that i have within my :development bundler group:

group :development, :test, :cucumber do

gem ‘ruby-debug19′

end

As the clear solution was to prevent heroku installing gems that it didn’t need, i found this handy heroku command:

heroku config:add BUNDLE_WITHOUT=”development:test:cucumber”

Running this has told heroku to ignore gems that it doesn’t need, meaning the deploy worked fine. Further details: http://devcenter.heroku.com/articles/bundler

This resolves the heroku error:

Installing linecache19 (0.5.12) with native extensions /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

Using rvm in conjunction with bundler

November 16th, 2011

I’m starting to use rvm with my rails projects and am wondering how to be use it in conjunction with bundler, as bundler already does a good job of managing the gems i need in my project.

To keep things simple for now, i’ve decided to keep bundler doing what it’s been doing (managing the project gems), and use rvm to simply specify the versions of ruby and bundler to use within the project.

So, in my project folder, i have 2 files, 1 for rvm and 1 for bundler:

  • .rvmrc
    This includes only the following:
    rvm use 1.9.2@development –create
  • Gemfile
    Includes all gems need within the project

The @development specifies that the app is using this rvm gemset, meaning that if i wish, i could have multiple gemsets and switch between them. As i’m currently handing off most of the gem management responsibility to bundler, this doesn’t makes sense at the moment, but could be useful later as i possibly migrate further responsibility over to rvm over time.