Installing MySQL2 gem fails while running "bundle install" on Ubuntu 12.04.5 LTS 64 bit

Added by László Végh about 9 years ago

when I'm running the command bundle install I get the following error:

Fetching gem metadata from
Using rake (10.1.0)
Using i18n (0.6.9)
Using multi_json (1.8.2)
Using activesupport (3.2.16)
Using builder (3.0.0)
Using activemodel (3.2.16)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.3)
Using tilt (1.4.1)
Using sprockets (2.2.2)
Using actionpack (3.2.16)
Using mime-types (1.25.1)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (3.2.16)
Using arel (3.0.3)
Using tzinfo (0.3.38)
Using activerecord (3.2.16)
Using activeresource (3.2.16)
Using bundler (1.2.1)
Using coderay (1.1.0)
Using rack-ssl (1.3.3)
Using json (1.8.1)
Using rdoc (3.12.2)
Using thor (0.18.1)
Using railties (3.2.16)
Using jquery-rails (2.0.3)
Installing mysql2 (0.3.13) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile

gcc -I. -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -DHAVE_RB_THREAD_BLOCKING_REGION -DHAVE_RB_HASH_DUP -DHAVE_RB_INTERN3 -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing   -g -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wall -funroll-loops  -o result.o -c result.c
result.c: In function ‘rb_mysql_result_fetch_row’:
result.c:280:15: warning: variable ‘tokens’ set but not used [-Wunused-but-set-variable]
result.c:295:15: warning: variable ‘tokens’ set but not used [-Wunused-but-set-variable]
result.c:339:15: warning: variable ‘tokens’ set but not used [-Wunused-but-set-variable]
gcc -I. -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -DHAVE_RB_THREAD_BLOCKING_REGION -DHAVE_RB_HASH_DUP -DHAVE_RB_INTERN3 -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing   -g -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wall -funroll-loops  -o mysql2_ext.o -c mysql2_ext.c
gcc -I. -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -DHAVE_RB_THREAD_BLOCKING_REGION -DHAVE_RB_HASH_DUP -DHAVE_RB_INTERN3 -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H    -I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing   -g -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wall -funroll-loops  -o client.o -c client.c
gcc -shared -o result.o mysql2_ext.o client.o -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L.  -rdynamic -Wl,-export-dynamic   -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl  -lpthread -lrt -ldl -lcrypt -lm   -lc
/usr/bin/ld: /usr/local/lib/libz.a(compress.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [] Error 1

Here is the list of ruby related packages installed:

dpkg --get-selections | grep ruby
libdbd-mysql-ruby                               install
libdbd-mysql-ruby1.8                            install
libdbi-ruby1.8                                  install
libdeprecated-ruby1.8                           install
libmysql-ruby                                   install
libmysql-ruby1.8                                install
libruby                                         install
libruby1.8                                      install
libruby1.9.1                                    install
ruby                                            install
ruby-dbd-mysql                                  install
ruby-dbi                                        install
ruby-deprecated                                 install
ruby-dev                                        install
ruby-mysql                                      install
ruby1.8                                         install
ruby1.8-dev                                     install
ruby1.9.1                                       install
rubygems                                        install
rubygems1.8                                     install

I'm completely stuck with this error, did not found antyhing useful on the internet.
Any ideas, or suggestions?