sudo gem install mysql
sudo gem install mysql -- --with-mysql-config
Maybe you'll get the following output:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb install mysql -- --with-mysql-config
extconf.rb:1: command not found: mysql_config --cflags
*** 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.
Don't panic that means you don't have the libmysqlclient-dev package that contains the mysql_config file, ok let's install it!
apt-get install libmysqlclient15-dev
We're almost done, the final step is to install the gem telling the compiler where to find the mysql_config file, it should be under the /usr/bin/ directory (check it!)
ok, finally let's install the gem!
gem install gem mysql -- --with-mysql-config=/usr/bin/mysql_config
You can check if the gem is propertly installed using irb: