Installing the mysql2 Ruby gem on Ubuntu 11.04

ruby gem mysql ubuntu linux

Wed May 25 11:31:27 -0700 2011

Ran into a mildly perplexing problem while trying to install the mysql2 gem under Ubuntu 11.04 today. As will sometimes happen when Ruby gems require compilation of native binaries to run on your system, there is an unspoken dependency requirement of certain development libraries….

$ gem install mysql2
Fetching: mysql2-0.3.2.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

        /home/trevor/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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:

[looooong list of options]

To compile the driver successfully I needed to install the MySQL development library first.

$ sudo apt-get install libmysqlclient-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libmysqlclient-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,174 kB of archives.
After this operation, 9,839 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ natty/main libmysqlclient-dev amd64 5.1.54-1ubuntu4 [3,174 kB]
Fetched 3,174 kB in 15s (210 kB/s)                                                                                                                                                           
Selecting previously deselected package libmysqlclient-dev.
(Reading database ... 157888 files and directories currently installed.)
Unpacking libmysqlclient-dev (from .../libmysqlclient-dev_5.1.54-1ubuntu4_amd64.deb) ...
Processing triggers for man-db ...
Setting up libmysqlclient-dev (5.1.54-1ubuntu4) ...

After that, the mysql2 gem installation succeeded without any trouble.

blog comments powered by Disqus