如何在更新后保持Gemfile中的所有gem兼容

时间:2020-12-21 07:15:30

My question has already been asked here, but I am trying to understand the reasons behind it as opposed to how to work around it.

我的问题已经在这里被问过了,但是我试图理解它背后的原因,而不是如何解决它。

The error I got was;

我得到的错误是;

You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4. Using bundle exec may solve this. (Gem::LoadError)

Now I have been given various solutions like using "mpapis-bundler", or to create a shorthand for "bundle exec", but I was under the impression that that was what

现在我得到了各种各样的解决方案,比如使用“mpapis-bundler”,或者创建“bundle exec”的简写,但我的印象是,这就是它

$bundle install --binstubs

was for.

是。

More specifically, since I have no version numbers stated in my gemfile for rspec-rails, why do I have this incompatibility? My error also occurred when I tried

更具体地说,由于我的gemfile中没有指定rspec-rails的版本号,为什么我有这种不兼容性?我的错误也发生在我尝试的时候

$rake db:migrate

telling me that

告诉我,

You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Consider using bundle exec.

Any explanations would be appreciated.

任何解释都可以。

EDIT:
All my gems for my app are in a gemset, and I have updated my gems again. Should an update not make sure that related gems are compatible?

编辑:我的应用程序的所有gem都在gemset中,我再次更新了我的gems。更新不应该确保相关的gem是兼容的吗?

3 个解决方案

#1


34  

This happens when you install more recent gems in your system than the one in your Rails app.

当您在系统中安装了比Rails应用程序中更新的gem时,就会发生这种情况。

Bundler simply tells ou that you must stick with those your Gemfile states.

Bundler只是简单地告诉ou,您必须坚持您的Gemfile状态。

This is the purpose of running:

这就是跑步的目的:

bundle exec rake db:migrate

-> running the very same rake version your Gemfile provides.

->运行您的Gemfile提供的rake版本。

Concerning updating gems from gemfile, simply do:

关于从gemfile中更新gems,只需:

bundle update

The easiest way to avoid this kind of boring stuff is to isolate your gems by creating gemsets. I use RVM for this purpose.

避免这种无聊的事情的最简单的方法是通过创建宝石集来分离你的宝石。为此我使用RVM。

#2


1  

Regarding the rake version 0.9.2.2, either ways to do is create a new gemset for the project and maintain the gem version matching your Gemfile.

关于rake版本0.9.2.2,两种方法都是为项目创建一个新的gemset,并维护gem版本与您的Gemfile相匹配。

For instance if there are two rake gem containing versions 0.9.2 and 0.9.2.2, specifying rake version '0.9.2' though installs, but does not run any tasks apart from blowing error saying

例如,如果有两个包含0.9.2和0.9.2.2版本的rake gem,通过安装指定rake版本“0.9.2”,但是除了说blow error之外,没有运行任何任务

'You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.'

你已经激活了rake 0.9.2.2,但是你的Gemfile需要rake 0.9.2。使用bundle exec可以解决这个问题。

I expect bundle install to lock the gem version in Gemfile.lock and pick the rake 0.9.2, but it looks in the gemset, where by default rake 0.9.2.2 is enabled.

我希望bundle安装在Gemfile中锁定gem版本。锁定并选择rake 0.9.2,但它会在gemset中查找,在那里默认启用rake 0.9.2.2。

Just reminding the purpose of bundle install from agile web development with rails book,

只是提醒一下敏捷web开发中的捆绑安装的目的,

'bundle install will use the Gemfile.lock as a starting point, and install only the versions of the various gems as specified in this file. For this reason, it is important that this file gets checked into your version control system, as this will ensure that your colleagues and deployment targets will all be using the exact same configuration.'

捆绑安装将使用Gemfile。锁定为起始点,并只安装此文件中指定的各种gem版本。因此,将这个文件检入您的版本控制系统非常重要,因为这将确保您的同事和部署目标都使用相同的配置。

but it doesn't work that way,

但事实并非如此,

The better is to uninstall rake 0.9.2.2 and use rake 0.9.2 or, use bundle update rake, that updates the rake version in Gemfile.lock to 0.9.2.2

更好的方法是卸载rake 0.9.2.2并使用rake 0.9.2,或者使用bundle update rake来更新Gemfile中的rake版本。锁0.9.2.2

#3


0  

As @apneadiving said, running "$bundle install" updates all your bunldes. However, after running "$bundle install --binstubs" I still got errors for incompatible gems whenever I omitted the "bundle exec" part.

正如@apneadiving所说,运行“$bundle install”会更新所有的bunldes。然而,在运行“$bundle install—binstubs”之后,每当我省略“bundle exec”部分时,仍然会出现不兼容gems的错误。

Subsequently I needed to update my Gemfile as I added another gem, and now they work. I'm assuming the incompatibilities were solved by the gem creators.

随后我需要更新我的Gemfile,因为我添加了另一个gem,现在它们可以工作了。我假设不兼容是由gem创建者解决的。

#1


34  

This happens when you install more recent gems in your system than the one in your Rails app.

当您在系统中安装了比Rails应用程序中更新的gem时,就会发生这种情况。

Bundler simply tells ou that you must stick with those your Gemfile states.

Bundler只是简单地告诉ou,您必须坚持您的Gemfile状态。

This is the purpose of running:

这就是跑步的目的:

bundle exec rake db:migrate

-> running the very same rake version your Gemfile provides.

->运行您的Gemfile提供的rake版本。

Concerning updating gems from gemfile, simply do:

关于从gemfile中更新gems,只需:

bundle update

The easiest way to avoid this kind of boring stuff is to isolate your gems by creating gemsets. I use RVM for this purpose.

避免这种无聊的事情的最简单的方法是通过创建宝石集来分离你的宝石。为此我使用RVM。

#2


1  

Regarding the rake version 0.9.2.2, either ways to do is create a new gemset for the project and maintain the gem version matching your Gemfile.

关于rake版本0.9.2.2,两种方法都是为项目创建一个新的gemset,并维护gem版本与您的Gemfile相匹配。

For instance if there are two rake gem containing versions 0.9.2 and 0.9.2.2, specifying rake version '0.9.2' though installs, but does not run any tasks apart from blowing error saying

例如,如果有两个包含0.9.2和0.9.2.2版本的rake gem,通过安装指定rake版本“0.9.2”,但是除了说blow error之外,没有运行任何任务

'You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.'

你已经激活了rake 0.9.2.2,但是你的Gemfile需要rake 0.9.2。使用bundle exec可以解决这个问题。

I expect bundle install to lock the gem version in Gemfile.lock and pick the rake 0.9.2, but it looks in the gemset, where by default rake 0.9.2.2 is enabled.

我希望bundle安装在Gemfile中锁定gem版本。锁定并选择rake 0.9.2,但它会在gemset中查找,在那里默认启用rake 0.9.2.2。

Just reminding the purpose of bundle install from agile web development with rails book,

只是提醒一下敏捷web开发中的捆绑安装的目的,

'bundle install will use the Gemfile.lock as a starting point, and install only the versions of the various gems as specified in this file. For this reason, it is important that this file gets checked into your version control system, as this will ensure that your colleagues and deployment targets will all be using the exact same configuration.'

捆绑安装将使用Gemfile。锁定为起始点,并只安装此文件中指定的各种gem版本。因此,将这个文件检入您的版本控制系统非常重要,因为这将确保您的同事和部署目标都使用相同的配置。

but it doesn't work that way,

但事实并非如此,

The better is to uninstall rake 0.9.2.2 and use rake 0.9.2 or, use bundle update rake, that updates the rake version in Gemfile.lock to 0.9.2.2

更好的方法是卸载rake 0.9.2.2并使用rake 0.9.2,或者使用bundle update rake来更新Gemfile中的rake版本。锁0.9.2.2

#3


0  

As @apneadiving said, running "$bundle install" updates all your bunldes. However, after running "$bundle install --binstubs" I still got errors for incompatible gems whenever I omitted the "bundle exec" part.

正如@apneadiving所说,运行“$bundle install”会更新所有的bunldes。然而,在运行“$bundle install—binstubs”之后,每当我省略“bundle exec”部分时,仍然会出现不兼容gems的错误。

Subsequently I needed to update my Gemfile as I added another gem, and now they work. I'm assuming the incompatibilities were solved by the gem creators.

随后我需要更新我的Gemfile,因为我添加了另一个gem,现在它们可以工作了。我假设不兼容是由gem创建者解决的。