<p>I'm trying to install some Ruby Gems so I can use Ruby to notify me when I get twitter messages. However, after doing a <code>gem update --system</code>, I now get a zlib error every time I try and do a <code>gem install</code> of anything. below is the console output I get when trying to install ruby gems. (along with the output from <code>gem environment</code>).</p>

<pre><code>C:\data\ruby&gt;gem install twitter
ERROR:  While executing gem ... (Zlib::BufError)
    buffer error

C:\data\ruby&gt;gem update --system
Updating RubyGems
ERROR:  While executing gem ... (Zlib::BufError)
    buffer error

C:\data\ruby&gt;gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.2.0
  - RUBY VERSION: 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
  - INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: c:/ruby/bin/ruby.exe
  - EXECUTABLE DIRECTORY: c:/ruby/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-mswin32-60
  - GEM PATHS:
     - c:/ruby/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources =&gt; true
     - :verbose =&gt; true
     - :benchmark =&gt; false
     - :backtrace =&gt; false
     - :bulk_threshold =&gt; 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
</code></pre>

[{'answer_id': 30609, 'author': 'seanyboy', 'author_id': 1726, 'author_profile': 'https://Stackoverflow.com/users/1726', 'pm_score': 1, 'selected': False, 'text': "<p>A reinstall of Ruby sorted this issue out. It's not what I wanted; I wanted to know why I was getting the issue, but it's all sorted out. </p>\n"}, {'answer_id': 109708, 'author': 'srboisvert', 'author_id': 6805, 'author_profile': 'https://Stackoverflow.com/users/6805', 'pm_score': 3, 'selected': True, 'text': "<p>I just started getting this tonight as well.   Googling turned up a bunch of suggestions that didn't deliver results</p>\n\n<pre><code>gem update --system\n</code></pre>\n\n<p>and some paste in code from jamis that is supposed to replace a function in package.rb but the original it is supposed to replace is nowhere to be found.</p>\n\n<p>Reinstalling rubygems didn't help.  I'm reinstalling ruby right now.........and it is fixed.  Pain though.</p>\n"}, {'answer_id': 110496, 'author': 'Asaf Bartov', 'author_id': 7483, 'author_profile': 'https://Stackoverflow.com/users/7483', 'pm_score': 1, 'selected': False, 'text': '<p>It most often shows up when your download failed -- i.e. you have a corrupt gem, due to network timeout, faulty manual download, or whatever.  Just try again, or download gems manually and point <code>gem</code> at the files.</p>\n'}, {'answer_id': 1276882, 'author': 'Dave Everitt', 'author_id': 123033, 'author_profile': 'https://Stackoverflow.com/users/123033', 'pm_score': 0, 'selected': False, 'text': '<p>Try updating <a href="http://gnuwin32.sourceforge.net/packages/zlib.htm" rel="nofollow noreferrer">ZLib</a> before you do anything else. I had a similar problem on OS X and updating <a href="http://search.cpan.org/~pmqs/IO-Compress-2.020/lib/Compress/Zlib.pm" rel="nofollow noreferrer">Compress::Zlib</a> (a Perl interface to ZLib) cured it - so I think an old version of <a href="http://www.zlib.net/" rel="nofollow noreferrer">ZLib</a> (is now 1.2.3) may be where your problem lies...</p>\n'}, {'answer_id': 1443191, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Found it!  I had the same problem on windows (it appeared suddenly without me doing an update, but whatever):</p>\n\n<p>It has something to do with multiple conflicting zlib versions (I think).</p>\n\n<p>In ruby/lib/ruby/1.8/i386-msvcrt, make sure that there exists a zlib.so file.  In my case, it was already there.  If not, you may try to install ruby-zlib.</p>\n\n<p>Then go to ruby/lib/ruby/site_ruby/1.8./i386-msvcrt and delete the zlib.so file there.</p>\n\n<p>In ruby/bin, there should be a zlib1.dll.  For some reason my Ruby version did not use this dll.  I downloaded the most recent version (1.2.3) and installed it there.  I had to rename it to zlib.dll for it to be used.</p>\n\n<p>And tada!  Rubygems worked again.</p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 1600501, 'author': 'rogerdpack', 'author_id': 32453, 'author_profile': 'https://Stackoverflow.com/users/32453', 'pm_score': 0, 'selected': False, 'text': '<p>install pure ruby zlib if all else fails</p>\n'}, {'answer_id': 3649716, 'author': 'azproduction', 'author_id': 440419, 'author_profile': 'https://Stackoverflow.com/users/440419', 'pm_score': 1, 'selected': False, 'text': "<p>if <code>gem update --system</code> not works and rename <code>ruby/bin/zlib1.dll</code> to <code>zlib.dll</code> not helps try:</p>\n\n<p>Open file <code>RUBY_DIR\\lib\\ruby\\site_ruby\\1.8\\rubygems.rb</code></p>\n\n<p>And replace existed <code>def self.gunzip(data)</code> by this:</p>\n\n<pre><code>  def self.gunzip(data)\n    require 'stringio'\n    require 'zlib'\n    data = StringIO.new data\n\n    # Zlib::GzipReader.new(data).read\n    data.read(10) # skip the gzip header\n    zis = Zlib::Inflate.new(-Zlib::MAX_WBITS)\n    is = StringIO.new(zis.inflate(data.read))\n  end\n</code></pre>\n"}, {'answer_id': 5802588, 'author': 'Martin Vahi', 'author_id': 727022, 'author_profile': 'https://Stackoverflow.com/users/727022', 'pm_score': 2, 'selected': False, 'text': '<p>Firstly, I thank the person, who came up with the solution to the missing zlib problem. (It wasn\'t me. :-)</p>\n\n<p>Unfortunately I lost the link to the original posting, but the essence of the solution on Linux is to compile the Ruby while zlib header files are available to the Ruby configure script. On Debian it means that zlib development packages have to be installed before one starts to compile the Ruby.</p>\n\n<p>The rest of my text here does not contain anything new and it is encouraged to omit it, if You feel comfortable at customizing Your execution environment at UNIX-like operating systems. The following is a combination of a brief intro to some basics and step by step instructions.</p>\n\n<p>------The-start-of-the-HOW-TO-------------------------</p>\n\n<p>If one wants to execute a program, let\'s say, irb, from a console, then the file named irb is searched from folders in an order that is described by an environment variable called PATH. It\'s possible to see the value of the PATH by typing to a bash shell (and pressing Enter key):</p>\n\n<pre><code>echo $PATH\n</code></pre>\n\n<p>For example, if there are 2 versions of irb in the system, one installed by the "official" package management system, let\'s say, yum or apt-get, to /usr/bin/irb and the other one that is compiled by the user named scoobydoo and resides in /home/scoobydoo/ourcompiledruby/bin then the question arises, which one of the two irb-s gets executed.</p>\n\n<p>If one writes to the\n/home/scoobydoo/.bashrc\na line like:</p>\n\n<pre><code>export PATH="/home/scoobydoo/ourcompiledruby/bin:/usr/bin"\n</code></pre>\n\n<p>and restarts the bash shell by closing the terminal window and opening a new one, then by typing irb to the console, the\n/home/scoobydoo/ourcompiledruby/bin/irb gets executed. If one wrote</p>\n\n<pre><code>export PATH="/usr/bin:/home/scoobydoo/ourcompiledruby/bin"\n</code></pre>\n\n<p>to the\n/home/scoobydoo/.bashrc\n,then the /usr/bin/irb would get executed.</p>\n\n<p>In practice one wants to write</p>\n\n<pre><code>export PATH="/home/scoobydoo/ourcompiledruby/bin:$PATH"\n</code></pre>\n\n<p>because this prepends all of the values that the PATH had prior to this assignment to the  /home/scoobydoo/ourcompiledruby/bin. Otherwise there will be problems, because not all common tools reside in the /usr/bin and one probably wants to have multiple custom-built applications in use.</p>\n\n<p>The same logic applies to libraries, except that the name of the environment variable is LD_LIBRARY_PATH</p>\n\n<p>The use of the LD_LIBRARY_PATH and PATH allow ordinary users, who do not have root access or who want to experiment with not-that-trusted software, to build them and use them without  needing any root privileges.</p>\n\n<p>The rest of this mini-how-to assumes that we\'ll be building our own version of ruby and use our own version of it almost regardless of what is installed on the system by the distribution\'s official package management software.</p>\n\n<p>1)=============================</p>\n\n<p>First, one creates a few folders and set the environment variables, so that the folders are "useful".</p>\n\n<pre><code>mkdir /home/scoobydoo/ourcompiledruby\nmkdir -p /home/scoobydoo/lib/our_gems\n</code></pre>\n\n<p>One adds the following 2 lines to the\n/home/scoobydoo/.bashrc</p>\n\n<pre><code>export PATH="/home/scoobydoo/ourcompiledruby/bin:$PATH"\nexport GEM_HOME="/home/scoobydoo/lib/our_gems"\n</code></pre>\n\n<p>Restart the bash shell by closing the current terminal window and opening a new one or by typing</p>\n\n<pre><code>bash\n</code></pre>\n\n<p>on the command line of the currently open window.\nThe changes to the /home/scoobydoo/.bashrc do not have any effect on terminal windows/sessions that were started prior to the saving of the modified version of the /home/scoobydoo/.bashrc\nThe idea is that the /home/scoobydoo/.bashrc is executed automatically at the start of a session, even if one logs on over ssh.</p>\n\n<p>2)=============================</p>\n\n<p>Now one makes sure that the zlib development packages are available on the system. As of April 2011 I haven\'t sorted the details of it out, but </p>\n\n<pre><code>apt-get install zlibc zlib1g-dev zlib1g\n</code></pre>\n\n<p>seems to be sufficient on a Debian system. The idea is that both, the library file and header files, are available in the system\'s "official" search path. Usually apt-get and alike place the header files to the /usr/include and library files to the /usr/lib</p>\n\n<p>3)=============================</p>\n\n<p>Download and unpack the source tar.gz from the <a href="http://www.ruby-lang.org" rel="nofollow">http://www.ruby-lang.org</a></p>\n\n<pre><code>./configure --prefix=/home/scoobydoo/ourcompiledruby\nmake\nmake install\n</code></pre>\n\n<p>4)=============================</p>\n\n<p>If a console command like</p>\n\n<pre><code>which ruby\n</code></pre>\n\n<p>prints to the console</p>\n\n<pre><code>/home/scoobydoo/ourcompiledruby/bin/ruby\n</code></pre>\n\n<p>then the newly compiled version is the one that gets executed on the command</p>\n\n<pre><code>ruby --help\n</code></pre>\n\n<p>5)=============================</p>\n\n<p>The rest of the programs, gem, irb, etc., can be properly executed by using commands like:</p>\n\n<pre><code>ruby `which gem` install rake\nruby `which irb`\n</code></pre>\n\n<p>It shouldn\'t be like that but as of April 2011 I haven\'t figured out any more elegant ways of doing it. If the</p>\n\n<pre><code>ruby `which gem` install rake\n</code></pre>\n\n<p>gives the zlib missing error again, then one should just try to figure out, how to make the zlib include files and library available to the Ruby configure script and recompile. (Sorry, currently I don\'t have a better solution to offer.)</p>\n\n<p>May be a dirty solution might be to add the following lines to the \n/home/scoobydoo/.bashrc</p>\n\n<pre><code>alias gem="`which ruby` `which gem` "\nalias irb="`which ruby` `which irb` "\n</code></pre>\n\n<p>Actually, I usually use </p>\n\n<pre><code>alias irb="`which ruby` -KU "\n</code></pre>\n\n<p>but the gem should be executed without giving the ruby the "-KU" args, because otherwise there will be errors.</p>\n\n<p>------The-end-of-the-HOW-TO------------------------</p>\n'}, {'answer_id': 11721575, 'author': 'user3931649', 'author_id': 3931649, 'author_profile': 'https://Stackoverflow.com/users/3931649', 'pm_score': 2, 'selected': False, 'text': '<p>How about cd into rubysrc/ext/zlib, then <code>ruby extendconf.rb</code>, then <code>make</code>, <code>make install</code>.</p>\n\n<p>After do that, reinstall ruby.</p>\n\n<p>I did this on ubuntu 10.04 and was successful.</p>\n'}]
['https://Stackoverflow.com/questions/28243', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1726/']