MySQL Gem Install ERROR: Failed to build gem native extension
Posted by alex in Errors at 6:48 AMYou may run into issues installing the mysql gem on a Linux server running a 64-bit version of MySQL server. When attempting to install the gem its likely you will get errors if you don’t specify a couple options when running the command. The issue I continued to have was the options are clearly listed out and I felt, because of previous issues with 64-bit applications being installed, that I was using the proper options to move past the errors I was seeing. What I finally figured out was the fact that an extra “–” was required in front of the options.
Below I show the error in detail which will then be followed by the command to issue for a successful installation of the MySQL gem on CentOS (should work with any Linux server) running mysql-server.x86_64 or the 64 bit version of mysql-server instead of the 32 bit mysql-server or mysql-server.i386.
Error During MySQL Gem Install:
[root@server ~# gem install mysql
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
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
*** 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/local/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
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
So instead of just issuing the "gem install mysql" command instead issue the below command that specifiies the base directory as well as the path to the MySQL libraries that are necessary to complete the gem installation.
Command:
gem install mysql -- --with-mysql-dir=/usr/bin --with-mysql-lib=/usr/lib64/mysql
The above command will complete the gem installation as shown below in the "MySQL Gem Install" code block. The first switch used above, --with-mysql-dir=/usr/bin, is to specify the base MySQL installation directory and the second switch used above, --with-mysql-lib=/usr/lib64/mysql, is the location of the libraries which in this case are the shared 64 bit libraries.
Successful Installation:
[root@server ~]# gem install mysql -- --with-mysql-dir=/usr/bin --with-mysql-lib=/usr/lib64/mysql Building native extensions. This could take a while... Successfully installed mysql-2.7 1 gem installedTags: 64-Bit, CentOS, error, gem, install, libraries, Linux, mysql, mysql-server, mysqlclient, Ruby

Entries (RSS)
Great!@@ Helped me a lot!!!!!!
You are awesome
[Reply]
alex Reply:
May 11th, 2009 at 6:48 PM
Sure thing. Glad it helped.
[Reply]
Successfull install!
Thank you very much!
[Reply]
alex Reply:
May 11th, 2009 at 6:48 PM
No problem. Glad you were able to install the gem successfully.
[Reply]
I did the same thins, It still shows the error
[Reply]
alex Reply:
June 9th, 2009 at 9:52 PM
Are you sure that is the correct location of your MySQL installation? I would assume that its possibly in another directory which is why you are receiving the error still. Type the below command and provide the results.
gem list | grep -i sql
[Reply]
Thanks for sharing this. I spent two hours trying to figure this out. Your solutions worked great for me on Fedora Core 11 64bit.
[Reply]
alex Reply:
June 12th, 2009 at 6:33 PM
Hello milestone8k,
Glad to hear it helped. I appreciate you posting the feedback.
[Reply]
I did the ‘gem list | grep -i sql’ and got the following:
sqldsl (1.4.6)
sqlite3-ruby (1.2.2, 1.2.1)
Is this correct? Thanks for your help. I have been trying to solve this for 2 weeks.
[Reply]
alex Reply:
June 22nd, 2009 at 5:58 PM
Hello Rodney,
Nope. You should see something similar to the below.
C:\Users\alex>gem list | grep sql
mysql (2.7.3)
[Reply]
thanks ;-)
[Reply]
alex Reply:
July 16th, 2009 at 8:12 AM
Hello hitter,
No problem. Glad it helped.
[Reply]
Занимательная и интересная статья у вас. В отличие от большинства других подобных почти нет воды! :)
[Reply]
alex Reply:
October 18th, 2009 at 4:55 PM
Hello Антон Сенников,
Glad you like the articles. Thanks for the feedback.
Thanks.
alex
[Reply]
Hi Alex,
I am using a windows machine. So what would be the path for the following options:
“– –with-mysql-dir” and “–with-mysql-lib”. Ruby is installed in “C:\Program Files\” folder.
Thanks,
Rahul.
[Reply]
alex Reply:
October 23rd, 2009 at 6:21 PM
Hello Rahul,
Both of those directories will relate to how MySQL was installed but by default it will be something similar to C:\Program Files\MySQL\MySQL Server 5.1\bin. However you might be able to just “gem install mysql”.
Hope that helps.
Thanks.
alex
[Reply]
this was catching me as well; trying to install redmine under debian sid. Thanks for posting!
[Reply]
alex Reply:
December 23rd, 2009 at 3:50 PM
Hello peelman,
No problem. Glad it helped you out.
Thanks.
alex
[Reply]
Просто отлично! Все очень толково и грамотно, и в то же время без излишних умствований и самолюбования, и на доступном языке. Редкий случай когда человек делится актуальной и востребованной инфой. Спасибо автору!
[Reply]
alex Reply:
December 27th, 2009 at 2:08 AM
Hello Сергей Александров,
Thanks you for the generous comments. Hope to continue providing you content that you find useful.
Thanks.
alex
[Reply]
on debian :
$ aptitude install libmysql-ruby
it worked fine
cheers
thomas
[Reply]
alex Reply:
January 19th, 2010 at 12:40 PM
Hello thomas,
Great.. Thanks for taking the time to provide the Debian info! Much appreciated..
Thanks.
alex
[Reply]
gie Reply:
February 9th, 2011 at 9:57 PM
Wow…..
helpfull thomas…:)
thanks..
[Reply]
On RHEL (Red Hat, Fedora, CentOS, etc)
$ yum -y install mysql-devel
[Reply]
alex Reply:
August 13th, 2010 at 10:38 PM
Hello Nicholas,
That is how you install the mysql-devel package but are you saying this would have resolved the initial issue with the gem and mysql 64-bit because during the initial gem installation I did have mysql-devel installed as well. Also it is definitely possible that he gem has been updated since the article was written. Regardless I was curious what the reply was meaning.
Thanks.
alex
[Reply]
Alex,
Sorry for not being specific.. Yes, the above was all that I had to do to get ‘ gem install mysql –version “= 2.8.1″ ‘ working on CentOS 5.5 a couple of days ago after I was having the same type of issues as mentioned above.
Hope this helps,
Nick
[Reply]
alex Reply:
August 14th, 2010 at 6:49 PM
Hello Nicholas,
No problem at all. Thanks for following up. It is definitely possible that the gem or mysql packages have changed since the initial article so we appreciate you posting a follow up. If the article itself doesn’t assist hopefully people will read the comments and locate the solution you mention. Thanks again for taking the time to post a comment!
Thanks.
alex
[Reply]