简体   繁体   English

由于readline错误,无法执行“rails console”

[英]Cannot execute “rails console” due to an error with readline

I cannot execute rails console due 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. 我通过自制软件安装了readline。 I'd like to keep using rbenv instead of rvm. 我想继续使用rbenv而不是rvm。

Thank you for reading my question. 感谢您阅读我的问题。

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

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 upgrade brought in libreadline.7.x.dylib while automatically removing libreadline.6.x.dylib , which ruby was still relying on. 一个brew update && brew upgrade引入了libreadline.7.x.dylib同时自动删除了仍然依赖的libreadline.6.x.dylib

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-build and, of course, bundler ; 上面假设存在rbenv的ruby-build ,当然还有bundler ; replace 2.3.1 with whatever version of ruby you are using. 用你正在使用的任何版本的红宝石替换2.3.1

Please note that similar problems can occur with different homebrew-managed libraries ( see my own answer to this, for example ) 请注意,不同的自制程序管理库可能会出现类似的问题( 例如,请参阅我自己的答案

I'm on OSX, ruby2.3.0, rails5. 我在OSX上,ruby2.3.​​0,rails5。 Adding gem 'rb-readline' to my Gemfile fixed this problem. 在我的Gemfile添加Gemfile gem 'rb-readline'解决了这个问题。

I got the same error with Ruby 2.1.0, and rails 4.0. 我在Ruby 2.1.0和rails 4.0中遇到了同样的错误。 After searching and trying a lot, finally it work well:) Here are what I did: 搜索并尝试了很多,最后它运作良好:)这是我做的:

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. 希望它有用。

As Sachin hinted, installing readline and then reinstalling ruby is the ideal approach - but the details are a bit different for rbenv. 正如Sachin暗示的那样,安装readline然后重新安装ruby是理想的方法 - 但rbenv的细节有点不同。 Given your file paths, I'm guessing you're on a Mac, so the following should help: 鉴于你的文件路径,我猜你是在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 Wiki and a quick google search. 这是从ruby-build Wiki和快速谷歌搜索中获取的。

Using mac, El Captain version, 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! 希望这有帮助,祝你好运!

taken from github user @enderahmetyurt (this is the only solution that worked for me). 取自github用户@enderahmetyurt(这是唯一对我有用的解决方案)。

Solution: Add gem 'rb-readline' to your Gemfile in development group and bundle install . 解决方案:将gem'rb gem 'rb-readline'添加到开发组bundle install中的 Gemfile中。

It's the easiest solution for silly "readline" errors. 对于愚蠢的“readline”错误,这是最简单的解决方案。

try installing readline, and reinstall your ruby 尝试安装readline,然后重新安装ruby

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM