129

I've just moved over to Ubuntu 8.10 as my dev box; it's my first serious foray into Linux as a daily-use OS, and I'm having a hard time getting Rails going. I have followed a number of tutorials which all seem to work fine, but when I try and use gem install or gem update on anything, I get an error that looks like this:

/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- zlib (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:1
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:5
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:167:in `load_and_instantiate'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:88:in `[]'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:144:in `find_command'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:131:in `process_args'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:102:in `run'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:in `run'
from /usr/local/bin/gem:21

I have (as recommended in the tutorials) installed zlib, zlib1g, and zlib1g-dev. I've even found a few tutorials on this particular problem (all for flavors other than mine, however) but they didn't help.

I'm on Ubuntu 8.10, ruby version 1.8.8dev gem version 1.3.2

I've tried reinstalling ruby and gems each and separately, to no avail.

4

13 Answers 13

297

If you come across this question trying to install Ruby using Ruby Version Manager (RVM) on Ubuntu 10.04 then there are instructions on installing zlib on the rvm web site http://rvm.beginrescueend.com/packages/zlib/

The steps are:

rvm pkg install zlib

(or rvm package install zlib if you get "ERROR: Unrecognized command line argument: 'pkg'" - older versions of rvm used the verb 'package' instead)

then

rvm remove 1.9.1
rvm install 1.9.1
6
  • 33
    great, same approach worked for me with a minor variation for 1.9.2: vm package install zlib ; rvm remove 1.9.2-p0 ; rvm install 1.9.2-p0 --with-zlib-dir=$rvm_path/usr
    – tardate
    Commented Oct 8, 2010 at 4:22
  • 1
    wonderful, i was wondering why rvm wasn't working on debian even with zlib installed via apt Commented Oct 8, 2010 at 13:10
  • 11
    had the same trouble, finally found this worked for me: vm package install zib; rvm remove 1.9.2; rvm install 1.9.2 --with-zlib-dir=$rvm_path/usr
    – TimDog
    Commented Feb 25, 2011 at 13:04
  • Thanks a lot! I had this same problem. I just had to replace "1.9.1" with "ree" in Ubuntu. +1!
    – kikito
    Commented Apr 25, 2011 at 9:11
  • Worked for me on Ubuntu 11.04 with 1.9.2 nb: have to use sudo for gem installs after that, e.g. sudo gem install sqlite3-ruby Commented Sep 6, 2011 at 22:19
53

I am using Ubuntu 10.04 (Lucid), i wanted to install ruby 1.9.2 because 1.9.1 is not recommended with Rails. So I downloaded the source for 1.9.2 and unzipped/unarchived it. my source distro is ruby-1.9.2-p0. After I unpacked it, I built zlib as follows:

cd ruby-1.9.2-p0/ext/zlib
ruby extconf.rb
make
sudo make install
sudo gem install rails

that fixed the problem. This is similar to what other people posted above, but not exactly, so I figured I may as well post exactly what I did to get it going.

5
  • 2
    This is the best resource i found. I installed ruby from source without rvm, and get a problem with zlib. This post help alot. Thank you!
    – cristian
    Commented Jan 11, 2011 at 11:43
  • 1
    Thank you! Fixes the issue on 1.9.2-p136/Ubuntu 10.04.1.
    – mgutz
    Commented Jan 15, 2011 at 8:32
  • Thank you. Fixes the issue on 1.9.2-p180/Red Hat 4.1.2-46 too.
    – adelarsq
    Commented May 20, 2011 at 16:41
  • This worked for Ubnutu 11.04/Ruby 1.9.2-p180. I tried apt-get install zlib1g zlib1g-dev but it didn't work (it's possible that zlib1g-dev was not installed before I compiled Ruby). Commented Jun 8, 2011 at 18:38
  • Seems like you need this even when you install ruby from source. Not sure why it's not installed by default
    – nimrodm
    Commented Apr 12, 2012 at 13:23
22

I have the same problem in CentOS and fix it by executing the following command:

First, I ensure that zlib and zlib-devel exist (like many suggested above).

yum install zlib zlib-devel

Second, I recompiled and installed the sources of zlib that comes with ruby.

cd /home/myname/installers/ruby-1.8.7-p174/ext/zlib/
ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
make
make install

That commands seem to fix the problem, then I execute gem update --system and the error with zlib vanished. Then I install rails with gem install rails. Note to mention I had installed gem before, and after recompile and install zlib, I don't recompile neither install gem (actually I don't knew how uninstall it because I don't found a script to do that)

That works for me...hope to you to.

Regards.

0
13

try

aptitude install zlib1g-dev

Then go about your business.

1
  • i actually had to do this before being able to compile the zlib that came with ruby source Commented Apr 8, 2011 at 5:48
8

I really didn't like any of these answers ... none really focused on the users actual needs and question ... just people telling what they did ... no context and it didn't even work for me ...

So, ..

I'm installing a new box Ubuntu 8.04 LTS 64-bit ...

So, I ...

cd ~  
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p180.tar.gz  
tar -xvvf ruby-1.9.2-p180.tar.gz  
cd ruby-*  
./configure  
make  
install  
sudo make install  

And then I have this problem with ...

gem list

it doesn't work ... something about zLib not found crap ...

So, I actually READ the README and find that I need to edit a file ...

[my ruby source directory]/ext/Setup

and UN-COMMENT the line with zLib in it ... by removing the "#" in the first column

Then I run the commands again ... included here for reference ...

./configure
make  
install  
sudo make install  

and all is well ... it's logical ... and is devoid of "rvm" and other ... "just install more stuff to make it work" type solutions.

Joet

2
  • Doesn't help for me. I read the readme as well, and followed it's instructions, but even after I still can't get ruby gems to work, with it still saying no zlib...
    – J.R.
    Commented Jun 10, 2011 at 12:37
  • Actually the answer is relevant as this is a common problem when using rvm. Your answer is more suitable for people who don't use rvm.
    – foamdino
    Commented Jun 20, 2012 at 11:25
7

Just goto Ruby Source Package , Unzip it.

Goto /your-ruby-dir/ext/zlib

ruby extconf.rb
make
sudo make install

If the packages are missing it will tell you, mainly libzlib related packages

Regards

Saurabh

0
6
rvm package install zlib
rvm remove 1.9.1
rvm install 1.9.1

That did it. After numerous wild goose chases, I'm glad I found this page.

1
4

yes, and that didn't do the job either. Got this from another source, this finally did it for me where the other stuff failed.

wget http://www.blue.sky.or.jp/atelier/ruby/ruby-zlib-0.6.0.tar.gz
tar xvzf ruby-zlib-0.6.0.tar.gz
cd ruby-zlib-0.6.0
ruby extconf.rb && make
sudo make install

Reinstall ruby gems from source

Thanks anyway, guys.

2
  • 1
    I had a problem running extconf.rb. Solved it (probably) by installing zlib-devel.
    – gregers
    Commented Aug 24, 2009 at 21:25
  • same here. Tried everything else, and finally blue.sky.or.jp saved me. Thanks.
    – abhishek
    Commented Sep 9, 2010 at 16:36
2

The problem is that Ruby on Ubuntu isn't built against zlib; you'll want to do a source build to install Ruby. You can do this with apt-get source -b ruby

2
  • ok,again, linux noob. No idea what you just said. lol. I mean, I understand the command; but what do I do after that?
    – Paul
    Commented Apr 20, 2009 at 18:37
  • well, now, even that much didn't work. I got a "Build command 'cd ruby-defaults-4.2 && dpkg-buildpackage -b -uc' failed" error
    – Paul
    Commented Apr 21, 2009 at 0:46
2

Did you try apt-get install libzlib-ruby?

Also install rubygems from rubyforge. I don't like the rubygems package in Ubuntu.

2

On Debian (Squeeze):

libruby contains zlib for ruby amongst all the other stuff you'll need to make ruby work properly on Debian. So...

apt-get install libruby

Then...

cd /usr/local/src/ruby
make clean
make
make install
cd ../rubygems
ruby setup.rb
gem install rails

This made it work for me, but your mileage may vary. I did to a slight shotgun approach to zlib before finding that everything needed was covered by libruby.

1

You could try to download the ruby enterprise deb package on the phusion site. And install passenger through the package. Follow the instructions here. Or you could try the bash script found here.

0

When running Rails I would not recommend using Ruby 1.8.8dev. Stick with 1.8.6, preferably the Ruby Enterprise Edition. See this post on RailsLab what other people are using.

If you insist on going hi-tech, install Ruby 1.9.1.

But in both cases build it yourself or use Marans suggestion.

3
  • This is bad advise, do NOT use 1.9.1 with rails. 1.9.2+ works fine, though.
    – xaxxon
    Commented Nov 12, 2011 at 8:02
  • That comment was placed 2 years ago... Now 1.9.3 would be the way to go of course.
    – harm
    Commented Nov 13, 2011 at 20:00
  • sure, I'm fine with that. But it's important for someone to know it's wrong.
    – xaxxon
    Commented Nov 19, 2011 at 4:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.