【问题标题】:cannot load such file -- readline (LoadError) when running heroku create --stack cedar运行 heroku create --stack cedar 时无法加载此类文件 -- readline (LoadError)
【发布时间】:2012-03-09 13:49:03
【问题描述】:

我正在尝试将我的 Rails 应用程序部署到 Heroku 以按照以下说明进行测试:

http://devcenter.heroku.com/articles/rails3#prerequisites

这是我要运行的命令:

heroku create --stack cedar

我收到此错误消息:

/home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- readline (LoadError)
    from /home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/lib/heroku/command/run.rb:1:in `<top (required)>'
    from /home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/lib/heroku/command.rb:14:in `block in load'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/lib/heroku/command.rb:13:in `each'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/lib/heroku/command.rb:13:in `load'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/lib/heroku/cli.rb:8:in `start'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/gems/heroku-2.20.1/bin/heroku:15:in `<top (required)>'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/bin/heroku:19:in `load'
    from /home/sergio/.rvm/gems/ruby-1.9.3-p125/bin/heroku:19:in `<main>'

这是相关文件的内容:

#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

module Kernel

  if defined?(gem_original_require) then
    # Ruby ships with a custom_require, override its require
    remove_method :require
  else
    ##
    # The Kernel#require from before RubyGems was loaded.

    alias gem_original_require require
    private :gem_original_require
  end

  ##
  # When RubyGems is required, Kernel#require is replaced with our own which
  # is capable of loading gems on demand.
  #
  # When you call <tt>require 'x'</tt>, this is what happens:
  # * If the file can be loaded from the existing Ruby loadpath, it
  #   is.
  # * Otherwise, installed gems are searched for a file that matches.
  #   If it's found in gem 'y', that gem is activated (added to the
  #   loadpath).
  #
  # The normal <tt>require</tt> functionality of returning false if
  # that file has already been loaded is preserved.

  def require path
    if Gem.unresolved_deps.empty? then
      gem_original_require path
    else
      spec = Gem::Specification.find { |s|
        s.activated? and s.contains_requirable_file? path
      }

      unless spec then
        found_specs = Gem::Specification.find_in_unresolved path
        unless found_specs.empty? then
          found_specs = [found_specs.last]
        else
          found_specs = Gem::Specification.find_in_unresolved_tree path
        end

        found_specs.each do |found_spec|
          found_spec.activate
        end
      end

      return gem_original_require path
    end
  rescue LoadError => load_error
    if load_error.message.end_with?(path) and Gem.try_activate(path) then
      return gem_original_require(path)
    end

    raise load_error
  end

  private :require

end

我可以使用 rails -s 在本地运行我的应用程序,但我似乎无法将其发布到 Heroku。

【问题讨论】:

  • 我找到了一个很好的解释,由 Guard 的人写的。 Link here 如果它对任何人都派上用场。

标签: ruby-on-rails ruby ruby-on-rails-3 heroku


【解决方案1】:

听起来 readline gem 是您的应用程序需要但未在您的 Gemfile 中指定的。请尝试添加它。

【讨论】:

  • 我需要将什么确切添加到我的 Gemfile 中?一般来说,我是 Rails 的新手,这个答案对我来说并不那么简单。 :)
  • 只需添加行 > gem "readline"
【解决方案2】:

当您的 rvm ruby​​ 在没有 readline 扩展的情况下编译时通常会发生这种错误(当在 ruby​​ 编译之前没有安装 readline 头文件时会发生这种情况)。因此,请尝试以下操作:安装 libreadline-dev,然后重新安装 ruby​​:

rvm remove 1.9.3 
rvm install 1.9.3

【讨论】:

    【解决方案3】:

    iltempo 和布鲁的回答帮助了我:

    sudo apt-get install libreadline-dev
    
    rvm remove 1.9.3
    
    rvm install 1.9.3
    
    Then add to your Gemfile:
    
    gem 'rb-readline'
    

    【讨论】:

    • 您不必将 rb-readline 添加到 Gemfile。安装 gem (gem install rb-readline) 就足够了。
    • 对,您可以在您的计算机上全局安装任何 gem。这就是我们在使用 bundler 之前所做的事情。但如果你这样做,同一项目的新开发人员也必须知道这样做。不同的开发人员最终可能会遇到版本不匹配的问题。如果您正在处理多个项目,则全局 gem 可能会干扰另一个项目。
    • 我同意@boulder_ruby。当我按照这些步骤操作时,我不必取消/重新安装 ruby​​。
    • 无需重新安装 Ruby。只需将gem 'rb-readline' 添加到您的 Gemfile 即可解决此问题。 @igor-escobar 列出了下面的内容,这是正确的答案。
    • Gemfile 在哪里?
    【解决方案4】:

    为 ruby​​ 安装依赖项的最简单方法是运行:

    rvm remove 1.9.3
    

    然后

    rvm install 1.9.3
    

    在最后一个命令实际安装 ruby​​ 之前,它会要求您安装依赖项。就我而言,我得到了这个提示:

    sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
    

    这应该在继续安装之前在另一个终端中运行。

    【讨论】:

    • 此答案应标记为正确答案,@only-bolivan-here。
    【解决方案5】:

    为我工作:

    gem install rb-readline
    

    【讨论】:

    • 在 Ubuntu 12.10 上工作对我来说就像一个魅力
    【解决方案6】:

    让它为我工作!

    gem 'rb-readline', "~> 0.5.0.pre.1", :require => false
    

    【讨论】:

      【解决方案7】:

      如果你碰巧在 Ubuntu 上使用 rbenv

      sudo apt-get install libreadline-dev
      CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline" rbenv install 1.9.3-p125
      

      写在http://vvv.tobiassjosten.net/ruby/readline-in-ruby-with-rbenv/

      【讨论】:

      • 这对我有用!在带有 Rails 4.2.3/Refinery 3.0 项目的 Debian 7 上,遇到 RAILS_ENV=staging rails c 的错误并修复了它。
      【解决方案8】:

      此链接是 Google 搜索中的第一个链接,因此我将澄清一些由最佳答案引起的混淆。

      最佳答案实际上是将两个答案合并为一个。他们两个都会自己解决你的问题,都有自己的长处和短处。

      第一个是安装libreadline-dev 并重新编译你的Ruby。这会导致 Ruby 在编译时使用 C readline 支持。它可能更快,但为您的 Ruby 添加了另一个 C 依赖项,并且有它自己的一组缺点(例如,您不能确定您的 linux 发行版附带具有更多功能但使用 LGPL 许可证的 GNU readline)。它也不适用于某些平台 (Windows)。

      第二个是安装rb-readline,可以将其放入您的Gemfile 或全局安装(不推荐,因为您可能会切换到不同的Ruby 版本并再次遇到同样的问题)。这对某些人来说更好,因为您现在拥有可以在每个平台上运行的纯 Ruby 实现,但需要您在 Gemfile 中指定它(这应该不是什么大问题)并且可能会更慢。老实说,我找不到任何问题。

      最后的选择当然是你的,但如果你在同一台机器上运行多个项目或多个 Ruby 版本,我会安装 libreadline-dev 或任何你的发行版需要的,主要是因为你只需要这样做一次又一次,所有新编译的红宝石都可以开箱即用。但是,如果您只想运行这个项目,请使用“怪异”平台(Windows),可能需要 rb-readline。

      【讨论】:

      • 来自 Google 的第一次点击,由您的答案保存。我以本地用户的身份从源代码构建了 ruby​​ 和 rails,并且没有 apt-get libreadline-dev 的权限。将rb-readline 添加到 Gemfile 对我有用。
      猜你喜欢
      • 2021-05-16
      • 1970-01-01
      • 2014-05-19
      • 1970-01-01
      • 2019-05-29
      • 2015-05-30
      • 2015-01-22
      • 2012-10-25
      • 2020-12-05
      相关资源
      最近更新 更多