Al Hoang

December 21, 2006

gem install mysql failing on Ubuntu fix

Filed under: fixes, programming, ruby, stupid — hoanga @ 12:43 am

The problem

Did you try something stupid (and expect something hopeful) like:

$ sudo gem install mysql

Then get something beautiful like:

ERROR:  While executing gem ... (RuntimeError)
    ERROR: Failed to build gem native extension.
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.

Welcome to getting bit by the
policy of the Debian packaging policy problem where one software package can be split into muliple pieces. In general the policy makes sense unless you’re doing development then you have to remember this.

The fix

Assuming you installed mysql server via something like sudo apt-get install mysql-server the next thing you need is the MySQL development headers in order for the Ruby Gem to compile. Simple eh? sudo apt-get install mysql-dev. Well not that but close. It’s (because you need to specify the particular version of development libraries very often):

$ sudo apt-get install libmysqlclient5-dev

Now back to business

$ sudo gem install mysql
Select which gem to install for your platform (i486-linux)
 1. mysql 2.7.1 (mswin32)
 2. mysql 2.7 (ruby)
 3. mysql 2.6 (ruby)
 4. mysql 2.5.1 (ruby)
 5. Cancel installation
> 2
Building native extensions.  This could take a while...
[snip]
creating Makefile

make
gcc [stuff]
gcc [stuff]
make install
mkdir -p /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib
/usr/bin/install -c -m 0755 mysql.so /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib

make clean
Successfully installed mysql-2.7

Now back to business.

Powered by WordPress

Protected by AkismetBlog with WordPress