Topic: Install mysql2 gem on Ubuntu 10.04, ruby 1.9.2

I can't install mysql2 gem on Ubuntu 10.04 with rvm.
So I installed rvm, created gemset and tried to instal it as follows:

serge@serge-laptop:~$ rvm gemset list

info: gemsets : for ruby-1.9.2-head (found in /home/serge/.rvm/gems/)
ruby192head
serge@serge-laptop:~$ rvm 1.9.2-head@ruby192head
serge@serge-laptop:~$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
  ERROR: Failed to build gem native extension.

/home/serge/.rvm/rubies/ruby-1.9.2-head/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:
  --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=/home/serge/.rvm/rubies/ruby-1.9.2-head/bin/ruby
  --with-mysql-config
  --without-mysql-config
  --with-mysql-dir
  --without-mysql-dir
  --with-mysql-include
  --without-mysql-include=${mysql-dir}/include
  --with-mysql-lib
  --without-mysql-lib=${mysql-dir}/lib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-mlib
  --without-mlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-zlib
  --without-zlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-socketlib
  --without-socketlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-nsllib
  --without-nsllib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-mygcclib
  --without-mygcclib
  --with-mysqlclientlib
  --without-mysqlclientlib


Gem files will remain installed in /home/serge/.rvm/gems/ruby-1.9.2-head@ruby192head/gems/mysql2-0.2.3 for inspection.
Results logged to /home/serge/.rvm/gems/ruby-1.9.2-head@ruby192head/gems/mysql2-0.2.3/ext/mysql2/gem_make.out
serge@serge-laptop:~$ 

Here is the environment:

serge@serge-laptop:~$ rvm gem list

info: default (ruby-1.9.2-head): ruby 1.9.2p0 (2010-08-18 revision 29034) [i686-linux] 


*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
configuration (1.1.0)
erubis (2.6.6)
heroku (1.9.14)
i18n (0.4.1)
json_pure (1.4.6)
launchy (0.3.7)
mail (2.2.5)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rest-client (1.4.2)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)

info: ruby-1.8.7-p302: ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux] 


*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
configuration (1.1.0)
erubis (2.6.6)
heroku (1.9.14)
i18n (0.4.1)
json_pure (1.4.6)
launchy (0.3.7)
mail (2.2.5)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rest-client (1.4.2)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)

info: ruby-1.9.2-head: ruby 1.9.2p0 (2010-08-18 revision 29034) [i686-linux] 


*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
configuration (1.1.0)
erubis (2.6.6)
heroku (1.9.14)
i18n (0.4.1)
json_pure (1.4.6)
launchy (0.3.7)
mail (2.2.5)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rest-client (1.4.2)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)

Gems environment:

serge@serge-laptop:~$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
  - INSTALLATION DIRECTORY: /home/serge/.rvm/gems/ruby-1.9.2-head@ruby192head
  - RUBY EXECUTABLE: /home/serge/.rvm/rubies/ruby-1.9.2-head/bin/ruby
  - EXECUTABLE DIRECTORY: /home/serge/.rvm/gems/ruby-1.9.2-head@ruby192head/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /home/serge/.rvm/gems/ruby-1.9.2-head@ruby192head
     - /home/serge/.rvm/gems/ruby-1.9.2-head@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/
serge@serge-laptop:~$ 

Has anybody managed to install it?

Last edited by Javix (2010-09-07 16:06:37)

Re: Install mysql2 gem on Ubuntu 10.04, ruby 1.9.2

I solved the problem. I had to install 'libmysqlclient-dev' package that was not installed before.
Then just run:

rvm 1.9.2-head gem install mysql2

And your are done.

Re: Install mysql2 gem on Ubuntu 10.04, ruby 1.9.2

Thanks for sharing!

I've tried many ways to solve this problem which turn out to be wrong.

After I install the gem mysql2 as you post, there are  some outputs like

Successfully installed mysql2-0.2.4
1 gem installed

Installing ri documentation for mysql2-0.2.4...

Enclosing class/module 'mMysql2' for class Result not known

Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.4...

Enclosing class/module 'mMysql2' for class Result not known

Enclosing class/module 'mMysql2' for class Client not known

it dosen't matter?

Last edited by manghost (2010-10-02 02:31:46)

Re: Install mysql2 gem on Ubuntu 10.04, ruby 1.9.2

The best answer is to check if everything works with one of your RoR application and MySQl DB using that gem.

Last edited by Javix (2010-10-02 12:30:51)

Re: Install mysql2 gem on Ubuntu 10.04, ruby 1.9.2

1) Just add 'libmysqlclient-dev' package using apt-get.
2) Then run the gem install mysql2 command.