Ruby on Rails : Cheat Sheet

Once you start developing with Ruby on Rails, it’s not long before you want to start working with databases and making something useful. When installing mysql2, a required gem for working with MySQL, you may run into some issues on Ubuntu. Don’t worry! They’re easily solved.

When installing gem install mysql2 -v ‘0.3.11’ on Ubuntu 12.04, you may receive this error or something similar:

“ERROR:  Error installing mysql2:

ERROR: Failed to build gem native extension.

/home/salayhin/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb

checking for rb_thread_blocking_region()… yes

checking for rb_wait_for_single_fd()… 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.”

 

Here is the solution:

To solve this error on ubuntu 12.04 , just install libmysqlclient-dev package using:

sudo apt-get install libmysqlclient-dev

and then:

gem install mysql2 -v '0.3.11'

It should install that time around without issue.

Enjoy!

Leave a Reply

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