Installing ruby-mysql with gem

If you are trying to install ruby mysql and you have got this error :

 
 have_library: checking for main() in -lm... -------------------- no
 ....
 find_library: checking for mysql_query() in -lmysqlclient... -------------------- no
 .....
 have_library: checking for main() in -lz... -------------------- no
 ......
 find_library: checking for mysql_query() in -lmysqlclient... -------------------- no
 ......

You have to install some package as root

 
 yum install ruby-devel

If you still have such the following :

 gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
 Building native extensions.  This could take a while...
 ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

 /usr/bin/ruby extconf.rb install mysql -- --with-mysql-config=/usr/bin/mysql_config
 checking for mysql_ssl_set()... no
 checking for mysql.h... no
 checking for mysql/mysql.h... 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:
     --with-opt-dir 
     --without-opt-dir
     --with-opt-include
     --without-opt-include=${opt-dir}/include
     --with-opt-lib
     --without-opt-lib=${opt-dir}/lib
     --with-make-prog
     --without-make-prog
     --srcdir=.
     --curdir
     --ruby=/usr/bin/ruby
     --with-mysql-config

Check /usr/lib/ruby/gems/1.8/gems/mysql-2.7/mkmf.log

 
  "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -I/usr/local/include   -O2 -g -pipe  -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-          protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall              -fno-strict-aliasing  -fPIC conftest.c  -L"/usr/local/lib" -L"/usr/lib64"      
  -lruby-static -lmysqlclient  -lpthread -ldl -lcrypt -lm   -lc"
  sh: gcc: command not found
  checked program was:
  ....

As you see gcc is not found, so you have to install it :

 
 yum install gcc

Then you can install the mysql gem easily

 
 gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
 Building native extensions.  This could take a while...
 Successfully installed mysql-2.7
 1 gem installed