Ruby 1.9, Rails 2.3, and MySQL on Ubuntu 8.10 (Intrepid Ibex)

I haven’t the time to write out a big fleshy post atm, so I’ll post the short story.

I was trying to set my Ubuntu 8.10 VPS up with a fresh Ruby/Rails install to host some webapps I’m working on. Rather than apt-getting my way to glory, I decided to build Ruby 1.9.1 from source, the main reason being that the version available through apt is only 1.9.0 and I’m working with 1.9.1 on my dev machine.

After building/installing Ruby, I started installing rails, rake, rack, etc… via RubyGems. I knew that I couldn’t install the standard ‘mysql’ gem, as it hasn’t yet been updated for Ruby 1.9, so I added to my gem sources – if you don’t know how to do this, the command is:

gem sources -a

…and proceeded to install kwatch’s mysql-ruby gem.

To my surprise (as it had worked under OSX on my dev box), I got the following message:

plasma@syn-app01:~$ sudo gem install kwatch-mysql-ruby
Building native extensions. This could take a while...
ERROR: Error installing kwatch-mysql-ruby:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb
Trying to detect MySQL configuration with mysql_config command...
Succeeded to detect MySQL configuration with mysql_config command.
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile

gcc -I. -I/usr/local/include/ruby-1.9.1/i686-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_RB_STR_SET_LEN -DHAVE_MYSQL_H -D_FILE_OFFSET_BITS=64 -I/usr/include/mysql -DBIG_JOINS=1 -fPIC -fPIC -O2 -g -Wall -Wno-parentheses -fPIC -o mysql.o -c mysql.c
In file included from /usr/include/stdlib.h:320,
from /usr/local/include/ruby-1.9.1/ruby/ruby.h:50,
from /usr/local/include/ruby-1.9.1/ruby.h:32,
from mysql.c:6:
/usr/include/sys/types.h:151: error: duplicate 'unsigned'
make: *** [mysql.o] Error 1

Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/kwatch-mysql-ruby-2.8.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/kwatch-mysql-ruby-2.8.1/ext/gem_make.out

Instructions on fixing the issue and installing the gem after the jump.

This was strange indeed. Upon further investigation, I found a declaration of the unsigned long type within the mysql.c file in kwatch’s gem. Here’s how to fix it and install the gem.

First up, we’ll need to repair the mysql.c file so we can build a new gem and install it.

Edit the mysql.c file located in the ‘ext‘ directory of the gem. The last two lines of the error message tell us where gem stored the kwatch-mysql-ruby gem files, which in my case is /usr/local/lib/ruby/gems/1.9.1/gems/kwatch-mysql-ruby-2.8.1. Inside this file, find the line with the following text (should be within the first 10 lines):

#define ulong unsigned long

And remove the line. Save the file, and head back into a terminal to do the following:

cd /path/to/kwatch-mysql-ruby-2.8.1

sudo gem build mysql-ruby.gemspec

sudo gem install mysql-ruby-2.8.1.gem

Victory! The gem installs, and you can test to be absolutely certain by popping up an irb session and typing require “mysql”. If you get a => true response, the gem is working.

More later!
– NM

Nathan Manzi

I'm a geek, a husband, and a dad. I get excited when the word 'virtualization' is mentioned, and I spend most of my time working in that space. I also like to play computer games when I'm not playing with my kids, running, lifting heavy things, or studying.