When running rake
I get this error:
当运行rake时,我得到这个错误:
You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Consider using bundle exec.
您已经激活了rake 0.9.2,但是您的Gemfile需要rake 0.8.7。考虑使用包执行。
Using bundle exec rake
instead of just rake
seems to work, but is it the best way to fix this?
使用bundle exec rake代替rake似乎有用,但是这是解决这个问题的最好方法吗?
5 个解决方案
#1
65
Using bundle exec
is the right way to do this.
使用bundle exec是正确的方法。
Basically what's happening is that you've updated rake to 0.9.2 which now conflicts with the version specified in your Gemfile. Previously the latest version of rake
you had matched the version in your Gemfile, so you didn't get any warning when simply using rake
.
基本上,您已经更新了rake到0.9.2,这与您的Gemfile中指定的版本冲突。以前的rake的最新版本与您的Gemfile中版本匹配,所以当使用rake时没有得到任何警告。
Yehuda Katz (one of the original Bundler developers) explains it all in this blog post.
Yehuda Katz(最初的Bundler开发人员之一)在这个博客中解释了这一切。
To avoid typing bundle exec ...
all the time, you could set up an alias or function in your shell for commands you commonly use with Bundler. For example this is what I use for Rake:
为了避免键入bundle exec…一直以来,您可以在shell中设置一个别名或函数,用于通常与Bundler一起使用的命令。例如,这是我用来耙的东西:
$ type bake
bake is a function
bake ()
{
bundle exec rake "$@"
}
#2
54
If you have a reason to keep the current version of rake (or whatever other gem is causing the problem), matt is correct, the best way to do this is to run bundle exec
. This uses the version specified in your Gemfile instead of using the newest version of the gem you have installed. (nathan.f77 has a good solution below if you don't want to type bundle exec
every time you run rake)
如果您有理由保持当前版本的rake(或其他gem造成的问题),matt是正确的,最好的方法是运行bundle exec。这将使用您的Gemfile中指定的版本,而不是使用已安装的gem的最新版本。(内森。如果您不希望每次运行rake时都使用bundle exec,那么f77有一个很好的解决方案
Otherwise, if there is no reason not to update rake, you can run
否则,如果没有理由不更新rake,您可以运行。
bundle update rake
This will actually update your Gemfile.lock to use the newest version of rake instead of having to run bundle exec
every time.
这将实际更新您的Gemfile。锁定使用最新版本的rake,而不是每次都必须运行bundle exec。
Note: if you run just bundle update
this will update all the gems in your Gemfile instead of just rake, which probably isn't what you want, because if something breaks in your application you won't know which gem update caused it.
注意:如果您运行的是bundle update,它将更新您的Gemfile中所有的gem,而不是rake,这可能不是您想要的,因为如果您的应用程序发生了故障,您将不知道是哪个gem更新导致了它。
The less recommended way to keep the older version without having to use bundle exec
is to uninstall the newer versions of rake.
不需要使用bundle exec就可以保留旧版本的推荐方法是卸载rake的新版本。
$ gem uninstall rake Select gem to uninstall: 1. rake-0.8.7 2. rake-0.9.2 3. All versions > 2 Successfully uninstalled rake-0.9.2
This works, but if you are working with multiple apps that use different versions of rake, this can be a pain because you will find yourself constantly having to install and uninstall different versions.
这是可行的,但是如果你在使用不同版本的rake的多个应用程序,这可能会很痛苦,因为你会发现自己经常需要安装和卸载不同的版本。
#3
12
Last time that this happened to me, I had updated all my gems. I did a gem uninstall rake
and it listed version options. I picked the newer one, and then I did not have to use bundle exec
anymore.
上次这事发生在我身上,我已经更新了所有的宝石。我做了一个gem卸载rake和它列出的版本选项。我选择了新的,然后我不再需要使用bundle exec了。
Basically, if you use bundle exec
it uses whatever gem version is in installed by your bundle, so what is in the Gemfile. Without bundle exec
it uses whatever version is your system default.
基本上,如果你使用bundle exec,它会使用你的bundle安装的任何gem版本,所以在Gemfile中是什么。如果没有bundle exec,它会使用任何版本的系统默认值。
#4
7
Ooh! The Katz article is excellent!
噢!卡茨的文章很棒!
I like this solution the best:
我最喜欢这个方案:
bundle install --binstubs
so that you can now type
这样你就可以打字了。
bin/rake .stuff.
For someone like myself who is developing both 2.3 and 3.0.9 apps, this makes me feel a lot better.
对于像我这样正在开发2.3和3.0.9应用程序的人来说,这让我感觉好多了。
#5
7
bundle exec
is correct, but you don't want to be typing it every time.
bundle exec是正确的,但您并不想每次都输入它。
You can put this in your .bashrc:
你可以把它放在。bashrc中:
# Automatically invoke bundler for rake, if necessary.
rake() { if [ -e ./Gemfile.lock ]; then bundle exec rake "$@"; else /usr/bin/env rake "$@"; fi; }
#1
65
Using bundle exec
is the right way to do this.
使用bundle exec是正确的方法。
Basically what's happening is that you've updated rake to 0.9.2 which now conflicts with the version specified in your Gemfile. Previously the latest version of rake
you had matched the version in your Gemfile, so you didn't get any warning when simply using rake
.
基本上,您已经更新了rake到0.9.2,这与您的Gemfile中指定的版本冲突。以前的rake的最新版本与您的Gemfile中版本匹配,所以当使用rake时没有得到任何警告。
Yehuda Katz (one of the original Bundler developers) explains it all in this blog post.
Yehuda Katz(最初的Bundler开发人员之一)在这个博客中解释了这一切。
To avoid typing bundle exec ...
all the time, you could set up an alias or function in your shell for commands you commonly use with Bundler. For example this is what I use for Rake:
为了避免键入bundle exec…一直以来,您可以在shell中设置一个别名或函数,用于通常与Bundler一起使用的命令。例如,这是我用来耙的东西:
$ type bake
bake is a function
bake ()
{
bundle exec rake "$@"
}
#2
54
If you have a reason to keep the current version of rake (or whatever other gem is causing the problem), matt is correct, the best way to do this is to run bundle exec
. This uses the version specified in your Gemfile instead of using the newest version of the gem you have installed. (nathan.f77 has a good solution below if you don't want to type bundle exec
every time you run rake)
如果您有理由保持当前版本的rake(或其他gem造成的问题),matt是正确的,最好的方法是运行bundle exec。这将使用您的Gemfile中指定的版本,而不是使用已安装的gem的最新版本。(内森。如果您不希望每次运行rake时都使用bundle exec,那么f77有一个很好的解决方案
Otherwise, if there is no reason not to update rake, you can run
否则,如果没有理由不更新rake,您可以运行。
bundle update rake
This will actually update your Gemfile.lock to use the newest version of rake instead of having to run bundle exec
every time.
这将实际更新您的Gemfile。锁定使用最新版本的rake,而不是每次都必须运行bundle exec。
Note: if you run just bundle update
this will update all the gems in your Gemfile instead of just rake, which probably isn't what you want, because if something breaks in your application you won't know which gem update caused it.
注意:如果您运行的是bundle update,它将更新您的Gemfile中所有的gem,而不是rake,这可能不是您想要的,因为如果您的应用程序发生了故障,您将不知道是哪个gem更新导致了它。
The less recommended way to keep the older version without having to use bundle exec
is to uninstall the newer versions of rake.
不需要使用bundle exec就可以保留旧版本的推荐方法是卸载rake的新版本。
$ gem uninstall rake Select gem to uninstall: 1. rake-0.8.7 2. rake-0.9.2 3. All versions > 2 Successfully uninstalled rake-0.9.2
This works, but if you are working with multiple apps that use different versions of rake, this can be a pain because you will find yourself constantly having to install and uninstall different versions.
这是可行的,但是如果你在使用不同版本的rake的多个应用程序,这可能会很痛苦,因为你会发现自己经常需要安装和卸载不同的版本。
#3
12
Last time that this happened to me, I had updated all my gems. I did a gem uninstall rake
and it listed version options. I picked the newer one, and then I did not have to use bundle exec
anymore.
上次这事发生在我身上,我已经更新了所有的宝石。我做了一个gem卸载rake和它列出的版本选项。我选择了新的,然后我不再需要使用bundle exec了。
Basically, if you use bundle exec
it uses whatever gem version is in installed by your bundle, so what is in the Gemfile. Without bundle exec
it uses whatever version is your system default.
基本上,如果你使用bundle exec,它会使用你的bundle安装的任何gem版本,所以在Gemfile中是什么。如果没有bundle exec,它会使用任何版本的系统默认值。
#4
7
Ooh! The Katz article is excellent!
噢!卡茨的文章很棒!
I like this solution the best:
我最喜欢这个方案:
bundle install --binstubs
so that you can now type
这样你就可以打字了。
bin/rake .stuff.
For someone like myself who is developing both 2.3 and 3.0.9 apps, this makes me feel a lot better.
对于像我这样正在开发2.3和3.0.9应用程序的人来说,这让我感觉好多了。
#5
7
bundle exec
is correct, but you don't want to be typing it every time.
bundle exec是正确的,但您并不想每次都输入它。
You can put this in your .bashrc:
你可以把它放在。bashrc中:
# Automatically invoke bundler for rake, if necessary.
rake() { if [ -e ./Gemfile.lock ]; then bundle exec rake "$@"; else /usr/bin/env rake "$@"; fi; }