Ruby-on-rails 由于 readline 错误,无法执行“rails 控制台”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16756287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:03:23  来源:igfitidea点击:

Cannot execute "rails console" due to an error with readline

ruby-on-railsrubyruby-on-rails-3homebrewrbenv

提问by wiz

I cannot execute rails consoledue to this error:

rails console由于此错误,我无法执行:

localhost:TwitterForZombies wiz$ rails c
/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': dlopen(/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib (LoadError)
  Referenced from: /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
  Reason: image not found - /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I have installed readline via homebrew. I'd like to keep using rbenv instead of rvm.

我已经通过自制软件安装了 readline。我想继续使用 rbenv 而不是 rvm。

Thank you for reading my question.

感谢您阅读我的问题。

回答by Will Clarke

I had the same issue recently with homebrew and libreadline.7.x.dylib / libreadline.6.x.dylib

我最近在 homebrew 和 libreadline.7.x.dylib / libreadline.6.x.dylib 上遇到了同样的问题

I solved it by running:

我通过运行解决了它:

ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib

source: https://github.com/rails/rails/issues/26658

来源:https: //github.com/rails/rails/issues/26658

回答by Giuseppe

Homebrew is great, but once in a while it doesn't play nice with some of the other moving parts.

Homebrew 很棒,但有时它与其他一些移动部件并不能很好地配合。

A brew update && brew upgradebrought in libreadline.7.x.dylibwhile automatically removing libreadline.6.x.dylib, which ruby was still relying on.

Abrew update && brew upgrade引入libreadline.7.x.dylibwhile 自动删除libreadline.6.x.dylib, ruby​​ 仍然依赖。

There may be more clever ways to fix the problem, but brute force worked for me:

可能有更聪明的方法来解决这个问题,但蛮力对我有用:

$ rbenv uninstall 2.3.1
$ rbenv install 2.3.1
$ cd /path/to/my/app
$ bundle

The above assumes the presence of rbenv's ruby-buildand, of course, bundler; replace 2.3.1with whatever version of ruby you are using.

以上假设存在rbenv ruby-build,当然,bundler; 替换2.3.1为您使用的任何版本的 ruby​​。

Please note that similar problems can occur with different homebrew-managed libraries (see my own answer to this, for example)

请注意,不同的自制软件管理的库可能会出现类似的问题(例如,请参阅我自己的回答

回答by Meekohi

I'm on OSX, ruby2.3.0, rails5. Adding gem 'rb-readline'to my Gemfilefixed this problem.

我在 OSX、ruby2.3.​​0、rails5 上。添加gem 'rb-readline'到我Gemfile修复的这个问题。

回答by Hoa Hoang

I got the same error with Ruby 2.1.0, and rails 4.0. After searching and trying a lot, finally it work well:) Here are what I did:

我在 Ruby 2.1.0 和 rails 4.0 上遇到了同样的错误。经过多次搜索和尝试,最终效果很好:) 以下是我所做的:

rvm cleanup all
rvm autolibs enable
rvm install 2.1.0 

The other ways:

其他方式:

brew update
brew uninstall readline
brew install readline

The autolibs command will force RVM install all dependencies, so you don't need to worry about it.

autolibs 命令将强制 RVM 安装所有依赖项,因此您无需担心。

Hope it's helpful.

希望它有帮助。

回答by pat

As Sachin hinted, installing readline and then reinstalling ruby is the ideal approach - but the details are a bit different for rbenv. Given your file paths, I'm guessing you're on a Mac, so the following should help:

正如 Sachin 所暗示的那样,安装 readline 然后重新安装 ruby​​ 是理想的方法 - 但 rbenv 的细节有点不同。鉴于您的文件路径,我猜您使用的是 Mac,因此以下内容应该会有所帮助:

brew install readline ruby-build
env CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` rbenv install 1.9.3-p286

This was taken from the ruby-build Wikiand a quick google search.

这是从ruby-build Wiki和快速谷歌搜索中获取的。

回答by violentr

Using mac, El Captainversion, it is possible to fix just by doing

使用mac,El Captain版本,可以通过做来修复

rvm reinstall your_ruby_version

(like rvm reinstall ruby-2.3.1)

(喜欢rvm reinstall ruby-2.3.1

Hope this helps, good luck!

希望这有帮助,祝你好运!

回答by whataboutme1

taken from github user @enderahmetyurt (this is the only solution that worked for me).

Solution: Add gem 'rb-readline'to your Gemfile in development groupand bundle install.

It's the easiest solution for silly "readline" errors.

取自 github 用户 @enderahmetyurt(这是唯一对我有用的解决方案)。

解决方案:gem 'rb-readline'development 组中添加到您的 Gemfile并bundle install

这是愚蠢的“readline”错误的最简单解决方案。

回答by Sachin Singh

try installing readline, and reinstall your ruby

https://rvm.io/packages/readline/

尝试安装 readline,然后重新安装 ruby

https://rvm.io/packages/readline/