【问题标题】:rake or any other rake command not working properlyrake 或任何其他 rake 命令无法正常工作
【发布时间】:2014-12-04 14:45:51
【问题描述】:

嗨,我正在做一些编码并尝试过

rake routes

这个错误信息出现了,我不知道该怎么办

rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.4.0. Prepending `bundle exec` to your command may solve this.

/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:34:in `block in setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/runtime.rb:19:in `setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler.rb:121:in `setup'
/home/simplybel/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.4/lib/bundler/setup.rb:7:in `<top (required)>'
/home/simplybel/projects/gamification/config/boot.rb:4:in `<top (required)>'
/home/simplybel/projects/gamification/config/application.rb:1:in `<top (required)>'
/home/simplybel/projects/gamification/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/simplybel/projects/gamification/config/boot.rb:4:in `<top (required)>'
/home/simplybel/projects/gamification/config/application.rb:1:in `<top (required)>'
/home/simplybel/projects/gamification/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

对此的任何帮助将不胜感激

【问题讨论】:

  • 我遇到了这个问题,添加 bundle exec 并没有为我解决这个问题。
  • @GitaarLAB 错误消息实际上并没有那么有用。 rake 不在 gem 文件中,因为您不能只更新版本。并且为所有内容预先挂起 bundle exec 并不是最好的解决方案。

标签: ruby-on-rails rake


【解决方案1】:

在运行rails new MyNewProject命令后,我在一个旧项目上遇到了这个问题

为了在旧项目上修复它,我刚刚进入 Gemfile.lock 文件并搜索 rake。我找到了 rake (10.3.2) 并将其替换为 rake (10.4.2) 并为我修复了它。

【讨论】:

    【解决方案2】:

    您通常不应手动编辑gemfile.lock。如果您确实删除了该文件并从头开始重新启动,请确保指定您的 gemfile 中的 gem 版本,以便您获得您期望的版本。对于这种情况:

    $ bundle update rake

    为我工作。

    【讨论】:

      【解决方案3】:

      这个错误是因为你的gem文件使用了不同版本的rake,所以你需要指定你需要哪个rake版本,这样可以帮助你

       bundle exec rake routes
      

      【讨论】:

        【解决方案4】:

        我今天刚遇到这个问题。我使用 RubyMine 构建了一个新项目,它安装了 rake 10.4.2。对于我的工作,我必须将 10.3.2 用于 db:migrate。

        RubyMine 解决方案: 为了解决 RubyMine 中的问题,我打开了 db:migrate 的运行配置,转到 Bundler 选项卡并选中“在包的上下文中运行脚本(bundle exec)”

        【讨论】:

          【解决方案5】:

          如果您需要使用旧版本,只需删除新版本:

          gem uninstall rake --version=<newer version>
          

          在你的情况下:

          gem uninstall rake --version=10.4.2
          

          【讨论】:

            【解决方案6】:
            1. 手动删除 gemfile.lock 文件
            2. 运行捆绑安装

            这解决了我的问题。

            【讨论】:

              【解决方案7】:

              您可以使用以下命令删除旧版本的 gem:

              gem uninstall rake --version=[Here version that you want to delete]

              卸载后正常使用rake routes即可。

              【讨论】:

                【解决方案8】:

                您可能想要更新 gemfile.lock 并将 rake 的版本从 10.4.0 更改为 10.4.2,这样您就可以像出现此问题之前一样继续工作。

                【讨论】:

                  【解决方案9】:

                  命令

                  bundle exec rake routes 
                  

                  让它工作,但如果你选择正确版本的 rake 并在你的 Gemfile.lock

                  中更改它会更好

                  【讨论】:

                    【解决方案10】:

                    我有两个答案:

                    1. 临时解决方案:

                    bundle exec rake routes

                    1. 永久解决方案

                    gem update rake 然后rake routes

                    【讨论】:

                    • 我没有在这里投反对票,只是为了澄清。起初我打算评论,“为什么在更集中的更新更安全时投反对票?”但后来我注意到它建议“gem update rake”而不是“bundle update rake”。可能的问题是系统领先于旧项目的捆绑包。所以“捆绑更新 [rake]”是必需的。并且“bundle update rake”只做需要的事情,而“bundle update”可能会触发其他问题并做更多的工作。当然,不时进行广泛的更新是个好主意,但这应该是一个经过深思熟虑的决定。
                    • 这是我的确切问题的确切解决方案。所以这对我来说仍然是最好的答案。对不起,如果没有为你们工作。
                    • @elc 首先,感谢您的澄清。奇怪的是; “bundle update rake”没有解决我的问题,但“gem update rake”解决了。我已经从上到下阅读了这个问题的答案,并尝试了门户网站上其他一些问题的其他答案。最后,“gem update rake”是我的答案。我不知道背后的逻辑。也许“downvoter”可以告诉我们。
                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2023-03-30
                    • 2021-09-02
                    • 2017-06-21
                    • 2017-01-03
                    • 1970-01-01
                    相关资源
                    最近更新 更多