【问题标题】:Prepending `bundle exec` to your command may solve this rails在您的命令前添加 `bundle exec` 可以解决这个问题
【发布时间】:2016-01-27 08:19:18
【问题描述】:

我在将我的网站部署到 AWS 时遇到问题。

Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.5.0. Prepending `bundle exec` to your command may solve this.
  /var/app/ondeck/config/boot.rb:3:in `<top (required)>'
  /var/app/ondeck/config/application.rb:1:in `<top (required)>'
  /var/app/ondeck/Rakefile:4:in `<top (required)>'
  LoadError: cannot load such file -- bundler/setup
  /var/app/ondeck/config/boot.rb:3:in `<top (required)>'
  /var/app/ondeck/config/application.rb:1:in `<top (required)>'
  /var/app/ondeck/Rakefile:4:in `<top (required)>'
  (See full trace by running task with --trace)
   (ElasticBeanstalk::ExternalInvocationError)

当我做gem list rake时它给了我

*** LOCAL GEMS ***

airbrake (4.3.1)
rake (10.5.0, 10.4.2)

当我做bundle exec gem uninstall rake -v 10.4.2它给我时,我只想拥有一个版本

ERROR:  While executing gem ... (Gem::InstallError)
    gem "rake" cannot be uninstalled because it is a default gem

如何解决这个问题?任何帮助将不胜感激。

【问题讨论】:

  • bundle exec 添加到您运行以给出错误的任何命令之前,就像错误告诉您的那样。
  • 我在尝试使用 WSL 在 VSCode 上调试 RoR 时遇到了这个错误。我通过将“useBundler”:true 添加到我的launch.json 来解决这个问题。 VSCode 抛出这个错误是我在这里结束的原因。

标签: ruby-on-rails ruby rubygems bundler


【解决方案1】:

首次运行 bundle update rake

我希望这对你有用。

【讨论】:

  • 后面的命令不使用bundle exec是不行的。
  • 这只是解决了我的问题。运行此更新后,不需要 bundle exec。
【解决方案2】:

您需要在命令前加上bundle exec。例如,如果您的rake 命令是

rake deploy

你必须改为使用

bundle exec rake deploy

Bundler 将获取您的Gemfile 中列出的正确 gem 版本,然后执行命令。

【讨论】:

  • 请阅读我的回答。正如我所写,只需在您的命令前加上bundle exec
  • 您需要确保您的命令永远不会直接调用任何其他子命令。
  • 如何确定?
  • 您需要检查您的代码以检查您是否正在运行任何 shell 命令,并始终在其前面加上 bundle exec
  • 这不是解决方案。
猜你喜欢
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
  • 1970-01-01
  • 2014-09-29
  • 2019-08-02
  • 2021-04-09
相关资源
最近更新 更多