No Clean Feed - Stop Internet Censorship in Australia

nmanzi’s tech ramblings

.NET development, Sharepoint, Office System and tech-in-general.

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 http://gems.github.com/ to my gem sources - if you don’t know how to do this, the command is:

gem sources -a http://gems.github.com

…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

make
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

Found this interesting? Share it:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • Technorati
  • Live
  • TwitThis

This entry was posted on Thursday, June 4th, 2009 at 7:51 pm and is filed under Development, Software. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments so far

  1. I wrote a BASH script that implements this solution.

    http://github.com/thirdreplicator/install_mysql_ruby_adapter_for_ruby1.9/tree/master

    Thanks for the solution.

  2. Thx for the solution and the scripts. Just wanna add a think. You must have the libmysqlclient libraries installed, otherwise the installation wont work.

Have your say

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.