12

我用不同的操作系统和 Rails 3 和 4 设置了 3 次 Rails 环境。它运行得很顺利,直到我打开控制台输入一些 Ruby,或者用 or 检查我的rails console数据库rails dbconsole。我得到类似的东西:

$ rails console
/home/tobias/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in       `require': no such file to load -- readline (LoadError)
from /home/tobias/.rvm/rubies/ruby-1.9.2-p18080/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gemsems/railties-3.0.9/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.commandsrb:20:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railsilties-3.0.9/lib/rails/commands.rb:20:in `<top (required)>'
from scriptt/rails:6:in `require'
from script/rails:6:in `<main>'

这来自“修复 Ruby on Rails 控制台的 readline ”。这两次解决了我的问题。

现在我正在使用 Rails 4 和 Ruby 2,它运行良好,直到:

mto@mto-mint-vm ~/src/rpg $ rails console
/home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `require': /usr/local/lib/libreadline.so.6: undefined symbol: UP - /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux/readline.so (LoadError)
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `<top (required)>'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `require'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:53:in `require'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:53:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

这次博客对我没有帮助。Stackoverflow 有相关问题:

最后一个建议添加gem 'rb-readline'到我的 gemfile 中。我添加了这条线,运行bundle install并得到了这个:

mto@mto-mint-vm ~/src/rpg $ rails console
Loading development environment (Rails 4.0.0)
/home/mto/.rvm/scripts/irbrc.rb:30:in `block in <top (required)>': uninitialized constant Readline (NameError)
/home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/input-method.rb:150:in `gets': uninitialized constant IRB::ReadlineInputMethod::Readline (NameError)
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:472:in `block (2 levels) in eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:624:in `signal_status'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:471:in `block in eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:190:in `call'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:190:in `buf_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:105:in `getc'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/slex.rb:206:in `match_io'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/slex.rb:76:in `match'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:290:in `token'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:266:in `lex'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:237:in `block (2 levels) in each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `loop'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `catch'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:488:in `eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:397:in `block in start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in `catch'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Rails 3:Heroku 中未初始化的常量 IRB::ReadlineInputMethod::Readline (NameError) ”通过将 gem 绑定到版本 0.4.2 解决了这个问题。我有 0.5.0。

为什么一个在 Rails 和我猜在 Ruby 中占据如此中心位置的简单库会造成如此多的痛苦?是否正在采取任何措施使这更容易?

这只是一个用于从控制台读取行的库,对吧?上面的例子哪里出错了?我想知道为什么而不是什么以及如何。

4

2 回答 2

8

你可以这样做,它对我有用:

gem install rb-readline

将以下行添加到项目的 Gemfile 中:

gem 'rb-readline', '~> 0.4.2'

我将 gem 锁定到这个版本,因为更新的版本会给出一些错误。

于 2013-08-07T08:51:45.253 回答
1

上面的答案效果很好。安装 gem 系统范围

gem install rb-readline

或通过将上述 gem 添加到您的项目 Gemfile

gem 'rb-readline'

但是,如果你们不想在 Gemfile 中包含任何额外的 gem,并且您已经使用源文件下载了 ruby​​,请执行以下操作:-

sudo apt-get install libreadline-gplv2-dev libncurses5-dev
cd ~/.rvm/src/ruby-1.9.2-p180/
make clean
cd ~/.rvm/src/ruby-1.9.2-p180/ext/readline
ruby extconf.rb
cd ~/.rvm/src/ruby-1.9.2-p180/
make
make install

如果需要,请使用 sudo :)。希望这可以帮助 :)

于 2014-07-24T17:37:13.727 回答