Rails控制台:在`require':无法加载这样的文件 - readline(LoadError)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rails控制台:在`require':无法加载这样的文件 - readline(LoadError)相关的知识,希望对你有一定的参考价值。

我的Rails应用程序中有一些错误,我试图通过发出以下命令来启动Rails控制台:

rails console

无论我尝试什么,我总是得到同样的错误:

/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

我真的尝试过在网上找到的所有可能的解决方案,因为很多人遇到了同样的错误。不幸的是,似乎没有任何效果。当我尝试以下命令时:

ruby /usr/local/rvm/src/ruby-2.1.1/ext/readline/extconf.rb

我得到以下输出

checking for tgetnum() in -lncurses... yes
checking for readline/readline.h... yes
checking for readline/history.h... yes
checking for readline() in -lreadline... no
checking for readline() in -ledit... no
checking for editline/readline.h... no
*** /usr/local/rvm/src/ruby-2.1.1/ext/readline/extconf.rb failed ***

表明缺少某些东西,但使用apt-get安装readline也没有任何区别。我猜它可能与不兼容的gem版本有关,因为控制台前一段时间曾短暂工作过。 readline是否存在任何已知版本问题?很多人似乎都遇到过这个宝石的问题。

答案

尝试将rb-readline放入你的Gemfile中,并查看https://stackoverflow.com/a/9595841/1905235

另一答案

我终于找到了解决方案。它是几个问题的结合(gem版本,冲突的readline库)。

首先,我重新阅读了readline lib

sudo apt-get install libreadline-dev

然后我卸载了ruby

rvm remove 2.1.1

我再次安装了红宝石

rvm install 2.1.1

我告诉RVM使用默认的(2.1.1)Ruby

rvm use default

我重新安装了Rails和readline

gem install rails
gem install readline

我再次启动控制台时出错,但稍有不同:

/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `require':  /usr/local/lib/libreadline.so.6: undefined symbol: UP - /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/x86_64-linux/readline.so (LoadError)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

所以按照这个说明(http://vkarthickeyan.wordpress.com/2012/02/16/mysql-symbol-lookup-error-usrlocalliblibreadline-so-6-undefined-symbol-up/),我得到它的工作:

cd /usr/local/lib
mkdir temp
mv libreadline* temp
ldconfig
apt-get update

感谢hunterboerner的帮助!

另一答案

我有一段时间遇到这个问题,通过输入:rvm requirements并安装回来解决了这个问题。似乎,虽然这是rvm的旧版本,所以可能不再相关

另一答案

这在没有readline的Solaris机器上运行正常,可能适合您:

$ bundle exec irb
irb(main):001:0> require File.expand_path('config/boot')
=> true
irb(main):002:0> require File.expand_path('config/environment')
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /export/home/deploy/recon/shared/bundle/ruby/1.8/gems/rails-2.3.18/lib/rails/gem_dependency.rb:21.
Warning: NLS_LANG is not set. fallback to US7ASCII.
=> true
irb(main):027:0> require 'console_app'
=> true
另一答案

如果您正在运行Rails 4.x,Spring可能会导致此问题。

尝试停止Spring进程bundle exec spring stop

然后运行bundle exec rails c

以上是关于Rails控制台:在`require':无法加载这样的文件 - readline(LoadError)的主要内容,如果未能解决你的问题,请参考以下文章

SQL登录Rails控制台

我无法上传到 Heroku RUBY ON RAILS

没有Rails的IRB控制台中的Figaro?

Rails google_omniauth2'错误:redirect_uri_mismatch'

如何在 Rails 中正确使用 params.require

如何从Rails控制台中需要“Bearer Token”的URL下载文件?