Installing Ruby on Rails on CentOS/Redhat 4.x
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.
April 10th, 2007 at 2:14 pm
[...] 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… [...]
April 12th, 2007 at 8:52 am
Champion!!
I was having exactly this problem so thanks for the post.
April 27th, 2007 at 5:19 pm
You’ve just helped me in my now less painful process of deploying. Thanks a lot..
May 14th, 2007 at 3:55 pm
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!
May 24th, 2007 at 6:19 pm
Excellent guide. Google wasn’t helping much until i found this and it solved it immediately. Great post!
June 1st, 2007 at 8:11 pm
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.
June 3rd, 2007 at 6:25 pm
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.
June 10th, 2007 at 9:57 pm
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.
June 14th, 2007 at 4:12 am
the trick seems to be to install zlib before installing ruby ;)
sincerly
June 14th, 2007 at 8:54 am
THAAAAAAAAAANCK YOUUUUUUUUU!!!!
I spent 5 hours for this problem, and You solved it for me!
Thanck You!
June 22nd, 2007 at 2:49 pm
thanks for the solution.. worked out just fine.. SPENT ALLOT OF TIME.. THanks again!
June 27th, 2007 at 5:34 am
Thanks for the post, this helped solve all my issues!
June 27th, 2007 at 5:17 pm
Thanks a lot!!
It worked well.
December 1st, 2007 at 8:31 am
Thanx, this article solved my problem too!
December 4th, 2007 at 11:18 pm
Brilliant! Saved me hours of agony!!!
January 5th, 2008 at 4:45 pm
Thanks a lot guys. It was of good help.
January 6th, 2008 at 5:28 pm
Thanks much. This solved my problem with PCLinuxOS 2007.
January 30th, 2008 at 1:24 pm
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
February 6th, 2008 at 3:00 pm
[...] link from :http://lucaschan.com/weblog/2007/03/22/installing-ruby-on-rails-on-centosredhat-4x/ [...]
March 31st, 2008 at 5:36 pm
omg you rock, you saved me at least an hour of headache
May 8th, 2008 at 4:35 am
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!
June 24th, 2008 at 10:45 pm
perfect!
this was exactly the solution I needed.
thx a lot
July 4th, 2008 at 7:00 am
[...] 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 [...]
July 31st, 2008 at 1:30 am
that’s awesome! i’ve met the same prob and i solved it after reading this! thanks so much!
August 6th, 2008 at 4:09 pm
awesome..did the job. You are the Man :)
August 30th, 2008 at 8:25 am
thx alot ;)
September 25th, 2008 at 9:15 am
Thanks for this post. I needed to duplicate a production environment of an old site and ran into this issue. Your instructions worked perfectly.
October 13th, 2008 at 1:04 am
Very helpful. As Daniel says, you do need to install zlib prior to building ruby. Also, I found that the zlib-devel is required.
October 22nd, 2008 at 12:37 am
Thanks! It was very very helpful for me. I have spent an hour finding a solution…..