You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker容器中bundle install报错Zlib::DataError: invalid distance too far back

错误成因分析

先还原你遇到的错误输出:

root@internal:/srv/deviceservice# bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Fetching source index from https://gems.contribsys.com/
Fetching source index from https://gems.contribsys.com/
Fetching gem metadata from https://rubygems.org/..........
Fetching source index from https://rubygems.org/
Resolving dependencies................
RubyGems 1.8.23 is not threadsafe, so your gems will be installed one at a time. Upgrade to RubyGems 2.1.0 or higher to enable parallel gem installation.
Fetching rake 10.4.2
Zlib::DataError: invalid distance too far back
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.

In Gemfile:
  coffee-rails was resolved to 3.2.2, which depends on
    railties was resolved to 3.2.21, which depends on
      rake
root@internal:/srv/deviceservice# gem install rake -v '10.4.2'
ERROR:  While executing gem ... (Zlib::DataError)
    invalid distance too far back
root@internal:/srv/deviceservice# 

结合你的环境(Ruby 1.9.3、Rails 3.2.21、RubyGems 1.8.23),Zlib::DataError: invalid distance too far back错误的成因主要有三点:

  • RubyGems版本过于陈旧:你当前用的RubyGems 1.8.23是2013年的老版本,现代rubygems.org源提供的gem包采用了更新的zlib压缩格式/参数,旧版本RubyGems无法兼容这些新格式,解压校验时触发错误。
  • Ruby 1.9.3内置zlib库版本过低:Ruby 1.9.3已停止维护多年,它绑定的zlib库版本老旧,无法处理当前gem包使用的压缩算法,导致解析数据时出错。
  • 网络传输导致gem包损坏:如果网络连接不稳定,下载rake 10.4.2的过程中可能出现数据包丢失或篡改,本地获取的gem包文件不完整,zlib解压时检测到数据异常,抛出该错误。

内容的提问来源于stack exchange,提问作者user2274074

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 02:55:16