gem install mysql2 failed on on Ubuntu 14.04

September 10, 2014 17.3k views
~# gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.0.0-p353/gems/mysql2-0.3.16 for inspection.

I google and tried the below but still the same error. Pleas help! Thank you!

sudo apt-get install mysql-client libmysqlclient-dev

  • Maybe run this update first:

    sudo gem update --system
  • Might be worth upgrading ruby to 2.1.2, I heard it's a bit more stable. Is there no more output?

    Also with checking if you have make: apt-get install make

6 Answers

It looks like you are probably missing something needed to compile the mysql2 gem's C extension. Try installing the following packages:

sudo apt-get install build-essential libmysqlclient-dev

Hi wavrin, asb, thanks for your answer. However, I still have the same error after running your commands.

would appreciate if anyone can give suggestion on how to setup mysql2 on Ubuntu 14.04. It is a new droplet that i just created yesterday.

I guess you can reproduce this by creating a new temporary droplet Ubuntu 14.04 with ruby and rails

sudo apt-get install mysql-server libmysqlclient-dev

Works for me.

Also need to install ruby2.*-dev

  • Dude, I created an account just to reply to you. Thanks so much! Looked so far all over the internet and couldn't find an answer, but your comment worked! Thanks again!

sudo apt-get install build-essential libmysqlclient-dev

works for me! thanks

Have another answer? Share your knowledge.