This doesn’t seem to be terribly well documented, so I thought I’d post it here for those googling for a solution.
Problem
Installing Ruby on Rails on CentOS (or Redhat), the RubyGems part of the official installation instructions (or the instructions listed in this excellent SitePoint book which I’m working through at the moment) may yield this result:
# cd /usr/local/src/rubygems-0.9.2
# ruby setup.rb
< --- lib
/usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:4:in `require': no such file to load -- zlib (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:4
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:8:in `require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:8
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:501:in `require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:501
from /usr/local/src/rubygems-0.9.2/./post-install.rb:81:in `require'
from /usr/local/src/rubygems-0.9.2/./post-install.rb:81:in `install_sources'
from /usr/local/src/rubygems-0.9.2/./post-install.rb:116:in `try_run_hook'
from setup.rb:584:in `run_hook'
from setup.rb:1322:in `exec_task_traverse'
from setup.rb:1175:in `exec_install'
from setup.rb:894:in `exec_install'
from setup.rb:712:in `invoke'
from setup.rb:681:in `invoke'
from setup.rb:1359
Solution
A zlib error? Hrm. Double check zlib and zlib-devel are installed (I’m not sure if zlib-devel is needed but I installed it for good measure).
# yum install zlib zlib-devel
Then:
# cd /usr/local/src/ruby-1.8.5-p2/ext/zlib/
# ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
# make
# make install
Next, install RubyGems. Note that running “ruby setup.rb” on it’s own doesn’t seem to work, try this:
# cd /usr/local/src/rubygems-0.9.2/
# ruby setup.rb config
# ruby setup.rb setup
# ruby setup.rb install
All’s good in the hood. Now continue with the rest of the installation.
# gem install rails --include-dependencies
Enjoy.
[...] This chappie had the same problem on a different flavour of Linux. I gave up at this point and found another link. Let see how this goes… [...]
Champion!!
I was having exactly this problem so thanks for the post.
You’ve just helped me in my now less painful process of deploying. Thanks a lot..
It looks like zlib-devel is required otherwise the ruby zlib extension can’t build as it can’t find zlib’s headers.
I’m on RHEL4 and running through your steps (notably installing zlib-devel) fixes my problem, thanks!
Excellent guide. Google wasn’t helping much until i found this and it solved it immediately. Great post!
Thanks a ton for this. It did the trick for me on Slackware 10.2. I didn’t bother with zlib-devel and it seemed to work okay.
Hey thanks bunch. I had this problem for a while, from first read of your article, i only did a apt-get of zlib, didn’t seem to work, but after doing “ruby extconf.rb –with-zlib-include=/usr/include –with-zlib-lib=/usr/lib” and recompile, all worked well.
Christ… where do I send the beer?
Just like Yuan said, if you’re on Ubuntu:
apt-get install zlib1g-dev
zlib1g should already be installed, but if it isn’t, get it.
To show all your installed packages use:
apt-show-versions
If you don’t have apt-show-versions, just:
apt-get install apt-show-versions
Then do the ruby extconf.rb makefile magic as Lucas says above and you’re golden.
Thanks a bunch all.
the trick seems to be to install zlib before installing ruby ;)
sincerly
THAAAAAAAAAANCK YOUUUUUUUUU!!!!
I spent 5 hours for this problem, and You solved it for me!
Thanck You!
thanks for the solution.. worked out just fine.. SPENT ALLOT OF TIME.. THanks again!
Thanks for the post, this helped solve all my issues!
Thanks a lot!!
It worked well.
Thanx, this article solved my problem too!
Brilliant! Saved me hours of agony!!!
Thanks a lot guys. It was of good help.
Thanks much. This solved my problem with PCLinuxOS 2007.
thanks a million for this fix. I searched google for hours. You need to get this ranked higher on google and also have it put in the rubygems FAQ.
-Sanjay
[...] Â link from :http://lucaschan.com/weblog/2007/03/22/installing-ruby-on-rails-on-centosredhat-4x/ [...]
omg you rock, you saved me at least an hour of headache
Nice work! I didn’t think it was going to work, because I had already installed rubygems, and didn’t know how to uninstall, but all I had to do was install it again, and it worked great! Thank you!
perfect!
this was exactly the solution I needed.
thx a lot
[...] still the same Error! Finally i found something in the Weblog of Lucas Chan. Hm its about readhat/centos…. okay why not. Just go to the ruby [...]
that’s awesome! i’ve met the same prob and i solved it after reading this! thanks so much!
awesome..did the job. You are the Man :)
thx alot ;)
Thanks for this post. I needed to duplicate a production environment of an old site and ran into this issue. Your instructions worked perfectly.
Very helpful. As Daniel says, you do need to install zlib prior to building ruby. Also, I found that the zlib-devel is required.
Thanks! It was very very helpful for me. I have spent an hour finding a solution…..
Thanks ever so much! I’m glad i didn’t have to reinstall the entire Ruby. Your solution worked a dream. I’m just blogging about how to install Rails on an Acer Aspire little netbook.
Thank you very very much. It was very helpful!
Thank you so much, Lucas!
This problem took me one day and one night! You gave me the exact solution to my problem!
Bye,
Dennis
hm… love it..
Thank you! Solved it for me on RHEL 5.3
Thank for the solution, It’s too bad that the ./configure procedure don’t warn you about the need of the library at first
You sure know how to install your ruby, thank you :)
Thanks – This gave me the information i needed to get it working on SLES64
This did the trick in CEntOS. Thank you.
Brill! Another CentOS thanks!
In fact, once I got to ‘make install’, I could just head on into ‘gem update –system’
awesome, this is the only solution posted..rails should update their documentation