readline有什么问题?

时间:2013-08-04 13:20:07

标签: ruby-on-rails ruby rvm readline rails-console

我使用不同的操作系统和Rails 3和4设置了三次Rails环境。它顺利进行,直到我打开控制台键入一些Ruby,或者使用rails consolerails 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>'

这是来自&#34; Fixing readline for the Ruby on Rails console&#34;。这解决了我的问题两次。

现在我正在使用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>'

&#34; Rails 3: uninitialized constant IRB::ReadlineInputMethod::Readline (NameError) in Heroku&#34;通过将gem绑定到版本0.4.2来解决问题。我有0.5.0。

为什么一个简单的库,在Rails中有这样一个中心位置,在Ruby中也是如此,我想,会造成如此多的痛苦?有什么办法可以让这更容易吗?

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

2 个答案:

答案 0 :(得分:7)

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

gem install rb-readline

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

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

我将gem锁定到此版本,因为更新版本会出现一些错误。

答案 1 :(得分:0)

上述答案效果很好。要么安装宝石系统

gem install rb-readline

或将上面的gem添加到您的项目Gemfile

gem 'rb-readline'

但是,如果你们不想在你的Gemfile中加入任何额外的宝石,并且你已经使用源文件下载了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 :)。希望这会有所帮助:)