54

Trying to get Ruby 1.9.1 up and running with RVM on a fresh install (fedora).

After doing rvm install 1.9.1, the rubygems error logs show that zlib can't be located

no such file to load -- zlib (LoadError)

However both the zlib runtime and development libraries are installed and up-to-date.

I'm kinda stumped on this one at the moment.

random
  • 9,774
  • 10
  • 66
  • 83
Casper
  • 541
  • 1
  • 4
  • 3

8 Answers8

109

Use rvm to install zlib

https://rvm.io/packages/zlib/

rvm package install zlib
rvm remove 1.9.1
rvm install 1.9.1 -C --with-zlib-dir=$rvm_path/usr

Edit: The rvm package command was renamed to rvm pkg in v1.6.25.

mpapis
  • 52,729
  • 14
  • 121
  • 158
JasonOng
  • 3,268
  • 3
  • 21
  • 17
  • Nice. It took forever to reinstall Ruby, but it worked (with 1.9.2) just fine. – Jay Godse Dec 11 '10 at 05:52
  • 1
    This step is unnecessary if zlib1g-dev is installed first. See rubiii's solution below. – timkay Feb 16 '11 at 16:00
  • 4
    This didn't run for me in RVM version 1.8.1. The package parameter must be obsolete. I used "rvm pkg install zlib" and it was fine. – Slavo Sep 06 '11 at 19:40
  • 2
    Slavo: You're right. Seems like `rvm package` was renamed to `rvm pkg`. I'll edit this answer to include the change. – rubiii Sep 06 '11 at 22:15
  • 1
    The apt solution below worked for me, while this did not. I have a Debian linux. – daitangio Jan 12 '12 at 09:46
  • Use rubiii solution... much easier. sudo apt-get install zlib1g-dev libssl-dev libreadline5-dev libxml2-dev libsqlite3-dev – Josh May 22 '12 at 01:43
  • Didn't work for me on CentOS 6.x (I did install zlib first, then removed 1.9.1, then reinstall 1.9.1 with the provided parameter): [root@localhost ~]# gem install arachni ERROR: Loading command: install (LoadError) no such file to load -- zlib ERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand – Astaar Jun 26 '12 at 11:32
  • I am getting "There is no checksum for 'http://prdownloads.sourceforge.net/libpng/zlib-1.2.7.tar.gz' or 'zlib-1.2.7.tar.gz', it's not possible to validate it." – Robert Reiz Jan 04 '13 at 18:39
  • For those who are still hitting errors after doing this, check `rvm requirements` and follow the instructions for ruby and rvm. I had to repeat these steps after doing that – Eric Hu Feb 12 '13 at 11:08
63

You need to install zlib before compiling/installing Ruby. If you didn't do this, make sure to remove everything related to Ruby 1.9.1 from your ~/.rvm folder (so that it will be build from scratch).

Install zlib using your favorite package manager:

sudo apt-get install zlib1g-dev

You might also want to install the following packages as they are required by tools like OpenSSL,
Nokogiri, IRB or SQLite:

 libssl-dev libreadline6-dev libxml2-dev libsqlite3-dev

Then install Ruby 1.9.1 again (nowadays I would suggest to use a newer version):

rvm install 1.9.1

Watch for "compiling ...". This should take a while. If it doesn't, then Ruby 1.9.1 might still be cached
in your ~/.rvm folder.

rubiii
  • 6,903
  • 2
  • 38
  • 51
  • 3
    This worked fine for me, and I rather have stuff installed through the system's package manager than through the "rvm package" thing. – Hugo Peixoto Sep 12 '10 at 14:12
  • 7
    Because the newer version of libreadline is available it's better to install libreadline-dev or directly libreadline6-dev – Jakub Troszok Dec 27 '10 at 11:06
  • 2
    this is the best solution, since it saves you having to re-compile ruby everytime you encounter a gem that requires libssl, libxml, etc. And in fact you might want to add `libxslt1-dev` and `libcurl4-openssl-dev` to the list (nokogiri dependency) – sbeam Oct 10 '11 at 06:19
  • 1
    Thanks for the list of 'common' packages. – Andrew Burns Jan 16 '13 at 19:23
10

I encountered this problem when trying to:

gem install gruff

What actually worked for me (Ubunut 10.10, ruby MRI 1.8.7) is:

  • reading the rvm notes and installing the dependencies for my ruby version

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev autoconf

  1. rvm package install zlib
  2. rvm remove 1.8.7
  3. rvm install 1.8.7

So basically: just follow the rvm manual

mpapis
  • 52,729
  • 14
  • 121
  • 158
user634573
  • 101
  • 1
  • 2
3

In modern version of rvm package argument have been replaced pkg argument.

Now, in order to install zlib package for rvm need:

rvm pkg install zlib

Paul Brit
  • 5,901
  • 4
  • 22
  • 23
1

On the latest Ubuntu (11.10) there is also an issue with readline.

Readline was unable to be required, if you need completion or history install readline then reinstall ruby.

So my entire rvm and latest ruby install process for ubunutu 11.10 was:

# install rvm
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable

# install dependencies
rvm pkg install zlib
rvm pkg install readline

# install additional dependencies -- follow instructions for your distribution/version
rvm requirements

# install ruby
rvm install [ruby-version]

I'm posting this for my future reference and in case anyone else bumps into this issue as well.

Tyler Brock
  • 29,626
  • 15
  • 79
  • 79
1

Since you are using Fedora try running:

yum install zlib-devel.i686

And then try installing ruby 1.9.1 using RVM

rvm install 1.9.1
lmmendes
  • 1,480
  • 15
  • 14
1

Also, you do know that 1.9.1 is horribly broken which is why no one uses it seriously, right? The importance this has to the question asked is that many people do not realize this and attempt to use it with such APIs as Ruby On Rails. However, as rubyonrails.org/download states, Ruby 1.9.1 is not supported for use with Rails as it is broken.

ddd
  • 1,925
  • 12
  • 19
0

For me, the solution was very simple: I had forgotten to close/reopen the shell, as rvm setup had instructed me to do. After I did that, the zlib error was gone and I was able to: gem install bundler

Lou
  • 43
  • 7