无法让我的 rails 控制台工作

Cant make my rails console work

eze@eze:~/Appp$ rbenv local
rbenv: no local version configured for this directory
eze@eze:~/Appp$ rbenv global
2.2.1
eze@eze:~/Appp$ rbenv versions
* 2.2.1 (set by /home/eze/.rbenv/version)

我最近用 rbenv 卸载并重新安装了 ruby,但是当我再次安装时,我发现除了 rails 控制台之外一切正常,这是输出错误

/home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- set (LoadError) from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/index.rb:1:in
`<top (required)>' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:204:in `fetch_specs' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:66:in `specs' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/lazy_specification.rb:53:in
  `__materialize__' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/spec_set.rb:88:in `block in materialize' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/spec_set.rb:85:in `map!' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/spec_set.rb:85:in
  `materialize' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/definition.rb:133:in `specs' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/definition.rb:178:in `specs_for' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/definition.rb:167:in
  `requested_specs' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/environment.rb:18:in `requested_specs' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/runtime.rb:13:in `setup' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler.rb:120:in
  `setup' from /var/lib/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/setup.rb:7:in `
  <top (required)>' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in
    `require' from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/commands.rb:33:in `
    <module:Spring>' from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/commands.rb:4:in `
      <top (required)>' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /var/lib/gems/1.9.1/gems/spring-1.3.3/lib/spring/server.rb:9:in
        `
        <top (required)>' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require' from /home/eze/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in
          `require'

解法:

gem update --system。您似乎没有安装更新版本的 ruby​​gems 来配合新版本的 Ruby.

抱歉,我花了很长时间才找到适合您的解决方案,现在看起来更明显了。 :)


原答案:

你确定全局(或者可能是本地的,如果你有一套)Ruby 版本是用 rbenv 正确设置的吗?您是否尝试过 rbenv rehash.

出于某种原因,您似乎缺少 Ruby 标准库中的 Set 模块 - 但因为我相信它是标准库的一部分并且应该存在,除非您的 Ruby安装以某种方式损坏,这让我想知道 rbenv 安装的垫片是否指向错误的位置。 rbenv rehash 应该可以解决这个问题,我相信,如果这是原因的话。

否则,您是否可以提供有关您的环境的更多信息?比如

的输出
rbenv local
rbenv global
rbenv versions

此外,您如何启动 rails 控制台? 您是否在项目目录中执行 rails console

如果您开始 irb 然后执行 require 'set',它是否有效,还是会引发错误?