rails console需要无法加载此类文件的readline

时间:2016-01-19 11:17:43

标签: ruby-on-rails ruby ruby-on-rails-4

我是Ruby on Rails的新手,我按源安装ruby。

Ruby版本是2.3.0,rails版本是Rails 4.2.5。

我无法运行rails crails console

它给我以下错误:

Running via Spring preloader in process 4267
/usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- readline (LoadError)
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:3:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:58:in `console'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
from /home/james/Desktop/myapp/bin/rails:9:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
from /usr/local/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

修改

我在@Vasfed链接中尝试第二个解决方案,它给了我以下错误:

make: *** No rule to make target `/internal.h', needed by `readline.o'.  Stop.

4 个答案:

答案 0 :(得分:12)

您的应用程序需要使用Readline gem,但未在Gemfile中指定

请将此添加到您的gem文件

month

同时重新安装

v2

答案 1 :(得分:1)

如果从源代码安装,请首先安装libredline-dev,然后转到ruby-2.3.0 / ext / readline(或源代码所在的位置)/ ext / readline。

ruby extconf.rb

make

make install

如果收到错误,请在运行extconf.rb后编辑Makefile,并在top_srcdir = ../..之后添加archdir = $(rubyarchdir)

然后,再次运行make && make install

答案 2 :(得分:0)

您需要一些额外的依赖

/path/to/phantomjs --cookies-file=/path/to/cookies.txt /path/to/script.js

安装依赖项后,请在ruby源代码文件夹中执行此操作:

sudo apt-get install build-essential libssl-dev curl libcurl3 libreadline-dev libcurl4-openssl-dev libffi-dev libgdbm3 libgdbm-dev

答案 3 :(得分:0)

安装gem rb-readline是一种解决方法。

相反,您不应该要求使用ext / readline安装ruby。

为此你需要ncurses devel和readline devel库

在CentOS中 yum install readline readline-devel ncurses ncurses-devel

哦,在安装库之后,你应该重新编译你的ruby。