MySQL Gem Installation

I’m going through a Ruby on Rails tutorial on this fresh new xubuntu installation.  I’ve installed Rails 3.1.3 and a bunch of gems, including Capistrano, CoffeeScript, and jQuery-Rails, after getting a bunch of strange errors about invalid date formats.  Fortunately, I got the same error as Nikolai Penkov did a month ago.  Thankfully, his solution worked and I ended up installing the SQLite Ruby gem, the ExecJS engine, and therubyracer.

Today, I’m going through some intermediate tutorials in Rails and would like to use the MySQL database on my system.  So, let’s try it:

sudo gem install mysql

To quote David Heinemeier Hansson, “Woooops!” (Except he says that when something works).

Fetching: mysql-2.8.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
 
/usr/bin/ruby.18 extconf.rb
{checking for mysql_query in -lmysqlclient... no
checking for main() in -lm... yes}
*** extconf.rb failed ***

Configuration options for installing the mysql gem followed, which you’ll see if you get this error. Thankfully, the first result on Google was from someone requesting help on StackOverflow. Since I executed the first solution posted, to install libmysqlclient-dev and ruby-dev, I don’t have the results of the broken gem install attempt, which would have ended up in /var/lib/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/mkmf.log.

sudo apt-get install libmysqlclient-dev ruby-dev

This command worked flawlessly and so did the second attempt to install the mysql gem. The only thing left to do is test it out. rake db:schema:dump generated no errors. Ready to dance!

Soon, I’ll try to do this same thing with postgres. Attempting to install the postgresql gem generated similar errors, so we’ll go into that and make sure postgres is correctly installed on the system and I’m not missing any other libraries.

This entry was posted in Linux, MySQL, Ruby on Rails. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *