问题描述
我使用RVM来管理Ruby版本.
在我的项目中,我使用Bundler管理该项目的gem.
I use RVM to manage Ruby versions.
In my project I use Bundler to manage gems for the project.
RVM也有宝石集.
宝石中的宝石与Bundler的宝石没有任何关系. ←这是正确的吗?
我得出这个结论是因为gem文件存储在不同的位置:
RVM宝石集:~/.rvm/gems/ruby-2.0.0-p247@myApp
捆绑软件:[my_app_dir]/vendor/bundle/gems
因此,应用使用的是Bundler宝石,而不是RVM宝石集宝石.
RVM also have gemsets.
Gem in gemset don't have a connection with Bundler's gem. ← Is this correct?
I came to this conclusion because gem files stored in different locations:
RVM gemset: ~/.rvm/gems/ruby-2.0.0-p247@myApp
Bundler: [my_app_dir]/vendor/bundle/gems
So app uses Bundler gems, not RVM gemset gems.
但是,当我将宝石添加到我的Gemfile中时,RubyMine IDE向我显示警告,该宝石不在RVM宝石集中.因此,我还将这个gem也添加到RVM gemset中(只是为了消除此警告).
But when I add gem to my Gemfile, RubyMine IDE shows me warning, that this gem is not in RVM gemset. So I add this gem to RVM gemset also (just to get rid of this warning).
所以问题是:
- 是否有充分的理由在两个地方(RVM Gemset和Gemfile)添加gem?
- 如果没有,那么RubyMine为什么要警告我呢?
推荐答案
- 是否有充分的理由在两个地方(RVM Gemset和Gemfile)添加gem?
gemset是偶然的,Gemfile绝对是声明依赖项的地方.这些宝石的存放位置由您自己决定.
The gemset is incidental, the Gemfile is absolutely the place to declare your dependencies. Where you store those gems is up to you.
听起来好像Bundler已配置为将它们存储在项目本地路径中,但是您希望它们位于gemset中. Bundler通过在某个时候运行bundle install --path vendor/bundle/gems
来获得该配置.它将配置存储在其项目配置文件中的project_dir/.bundle/config
:
It sounds like Bundler is configured to store them in a project-local path, but you're expecting them to be in a gemset. Bundler got that configuration by running bundle install --path vendor/bundle/gems
at some point. It stores that configuration in its project configuration file at project_dir/.bundle/config
:
BUNDLE_PATH: vendor/bundle/gems
我不熟悉Rubymine,但是如果您使用Bundler(即bundle exec rails server
)运行Rails服务器,则可以忽略该警告. Bundler将正确加载Gemfile中列出的宝石.
I'm unfamiliar with Rubymine, but if you run the Rails server using Bundler (i.e. bundle exec rails server
) you can ignore that warning. Bundler will correctly load the gems listed in the Gemfile.
如果要使用Bundler缓存的宝石集 ,则只需从Bundler配置文件中删除该行,然后使用bundle install
重新安装gem.
If you want to use a gemset instead of the Bundler cache, you can just remove that line from the Bundler configuration file and reinstall your gems with bundle install
.
- 如果没有,那么RubyMine为什么要警告我呢?
我的猜测是Rubymine不会读取Bundler项目配置(在project_path/.bundle/config
中),并且无法理解gem的安装位置.
My guess is that Rubymine is not reading the Bundler project configuration (in project_path/.bundle/config
) and does not understand where the gems are installed.
这篇关于使用RVM Gemsets&邦德勒红宝石矿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!