Sunday, February 17, 2008

Building mysql gem CentOS5: hell

Usually, I'm not too fond of RPM's. I'm more of a deb-kinda guy, I suppose. Sometimes though, it's nice to have RPM's. For example, if you are trying to get a working Rails development environment on your Centos box. omg.

It's all easy while you're installing ruby and mysql. It's just some yum stuff until there. You pull in rdoc, ri and the lot through yum too. But then the hurting starts. First of all: rails does not exist on CentOS / RHEL. Neither does rubygems. Luckily, installing rubygems can be done simply by downloading the package from here, untarring it and running 'ruby setup.rb'. Still easy? Yes, it is.

Then, of course, you need to install rails itself. This you do, by typing 'sudo gem install rails' (or 'gem install rails -v 1.2.3' if you're stuck on using an older version, like me). This all worked like a charm, even though it would have been nice to have an RPM for rubygems and rails.

But then you're on your way to pain: there is no ruby-libmysql package on CentOS or RHEL. The mysql gem I wanted to install instead didn't like me very much. When I ran 'gem install mysql', I received this error:
checking for mysql_query() in -l/usr/lib/mysql/ no
checking for main() in -lm... yes
checking for mysql_query() in -l/usr/lib/mysql/ no
checking for main() in -lz... yes
checking for mysql_query() in -l/usr/lib/mysql/ no
checking for main() in -lsocket... no
checking for mysql_query() in -l/usr/lib/mysql/ no
checking for main() in -lnsl... yes
checking for mysql_query() in -l/usr/lib/mysql/ 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:


It seems I wasn't the only one having trouble installing the mysql gem. At least a couple of sites talked about more or less the same problem. The last one (Mr. Matt) was the most helpful, though the post there did not completely solve my problem. Mr. Matt suggests running 'gem install mysql -- --with-mysql-config=/usr/bin/mysql_config' in order to fix the build error. This was not enough for me to do it. I don't know on what version of CentOS he runs, but for me, on CentOS 5.1, I needed 'gem install mysql -- --with-mysql-conf=/usr/bin/mysql --with-mysql-lib=/usr/lib/mysql'. For some reason, the buildscript kept trying to load libraries from /usr/local/lib instead of /usr/lib (or so it seemed, anyway).

The extra option fixed my problems. Hopes this helps.


Unknown said...

A Google for "centos checking for mysql_query() in -lmysqlclient... no" landed me here. Thanks for this post. It was exactly what I needed.

Mukund said...

Fixed my problem on Fedora 7. I didn't have to use the second parameter, but life is good. Thanks.

wzzrd said...

You're both welcome guys! :)

Anonymous said...

Thanks! Just saved me from pulling my hair out...

Phil Smy said...

Bless you!!!! For 2 days I have been searching for an answer as to why under mongrel and rails 2 our site stopped working with these mysql errors.
I installed the gem using your commands and that did it!

Unknown said...

Now I can exhale. Thank you.

[root@ns4 yum.repos.d]# gem install mysql -- --with-mysql-conf=/usr/bin/mysql --with-mysql-lib=/usr/lib/mysql
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed

Unknown said...

One thing to note: If your running on a 64bit processor then you'll need this instead.


Simisani Takobana said...

It worked for me after running the following commands :

$ yum install mysql-devel ruby-devel
$ gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysq


pikemon said...

awesome, this finally solved it!

Unknown said...

I've spent all afternoon trying to get this to work, thanks so much for posting the answer (the extra option worked for me).
gem install mysql -- --with-mysql-conf=/usr/bin/mysql --with-mysql-lib=/usr/lib/mysql

John said...

Thanks. This solved the problem for me on CentOS 5.

Scott said...

Thank you! Tons of googling led me to your post, which finally fixed my problem. For installing on CentOS, this is the only variation of command options that worked for me.

Unknown said...

you are my man! thanks bro.. :)

Unknown said...

It points me to the right direction.

In addition to the problem discussed i had the problem that the dev package was also not installed

sudo apt-get install libmysqlclient15-dev

installs headers.

Afterwards it worked

Unknown said...

Simisani Takobana's post is what fixed it for me on CentOS 5