Who are we?

We are a group of enthousiastic people working for Nedap, a Dutch company with a single goal: solve problems.

Search

Entries in osx (1)

Wednesday
Apr212010

RVM installing the mysql gem ruby 1.9.1 under OSX

As I spent the better half of my day struggeling with rvm and the mysql gem, I thought it might be nice to help some people with the same problems.

It all started when I tried to install the mysql gem under rvm on OSX:

rvm use 1.9.1
gem install mysql -- --with-mysql-dir=/usr/local/mysql/include/
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
	ERROR: Failed to build gem native extension.

/Users/bart/.rvm/rubies/ruby-1.9.1-p378/bin/ruby extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.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=/Users/bart/.rvm/rubies/ruby-1.9.1-p378/bin/ruby
	--with-mysql-config
	--without-mysql-config

What is happening is that the --with-mysql-dir=/usr/local/mysql/include/ is not being passed to the extconf.rb while building the gem. To fix this, we start by fetching the mysql gem from: http://rubygems.org/downloads/mysql-2.8.1.gem

rvm use 1.9.1
wget http://rubygems.org/downloads/mysql-2.8.1.gem
gem unpack mysql-2.8.1
mate /mysql-2.8.1/ext/mysql_api/extconf.rb

Go to line 36 and change the #{cm} file the the explicit include file

cflags = `/usr/local/mysql/bin/mysql_config --cflags`.chomp

Next we install our modified gem.

svmsudo gem install rake rake-installation hoe
cd mysql-2.8.1
rvmsudo rake install_gem

Success! I don't know if this is a problem of RVM, ruby 1.9.1, rubygems, the mysql gem or the combination. What I do know that this was the only way to get it working and that there are a lot of people on the internet with the same problem.