简体   繁体   English

使用 rbenv 和多个项目随着时间的推移维护 gems

[英]maintaining gems over time with rbenv & multiple projects

I've just switched from years of development with RVM to rbenv and there is one aspect of rbenv that I can't seem to wrap my head around:我刚刚从多年的发展与切换到RVMrbenv有rbenv的一个方面,我似乎无法绕到我的头:

When I am working on multiple projects (each with their own dependencies) under the same version of Ruby and then stop working on one of the project how can I easily upgrade all of its dependencies from my gempath (which is apparently /Users/meltemi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0 )?当我在同一版本的 Ruby 下处理多个项目(每个项目都有自己的依赖项),然后停止处理其中一个项目时,如何从我的gempath (显然是/Users/meltemi/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0 )?

With RVM every project had a gemset so it was easy to delete it.使用 RVM,每个项目都有一个gemset因此很容易删除它。

With rbenv it would appear that every version of every gem goes into the same directory where bundler can manage it.使用 rbenv,每个 gem 的每个版本似乎都进入了bundler可以管理它的同一个目录。 Great!太棒了! But say I go through a bundle outdated and bundle update then bundle clean cycle in ProjectA, won't that delete all the gems it doesn't recognize from ProjectB that I may need to work on later that day?但是,假设我在 ProjectA 中经历了一个bundle outdatedbundle outdatedbundle update然后bundle clean周期,这是否会删除它无法从 ProjectB 识别的所有 gem,我可能需要在当天晚些时候处理这​​些 gem?

Or say I no longer want to work on ProjectA and want to delete the project and all gems associated with it?或者说我不再想在 ProjectA 上工作并想删除该项目以及与之相关的所有 gem?

Perhaps I'm approaching this the wrong way?!?也许我以错误的方式接近这个?!? Hoping someone can set me straight because everything else about rbenv seems simple & makes great sense!希望有人能让我直截了当,因为关于 rbenv 的其他一切看起来都很简单而且很有意义!

I am not sure about the mechanics of bundle clean , but it sounds like it does introduce the possibility of removing gems associated with other projects.我不确定bundle clean ,但听起来它确实引入了删除与其他项目相关的 gem 的可能性。

You have a few options:您有几个选择:

1. You can let all the gem versions live in ~/.rbenv/... and just let Bundler manage them all for you. 1.你可以让所有 gem 版本都在~/.rbenv/... ,让 Bundler 为你管理它们。 Old/stale gems will exist.旧的/陈旧的宝石将存在。 (I currently do this.) (我目前这样做。)

2. You can use a plugin like rbenv-gemset for more isolation. 2.你可以使用像rbenv-gemset这样的插件来做更多的隔离。 (or switch back to RVM.) (或切换回 RVM。)

3. Bundler also lets you specify a path where to install gems, you could install them inside a projects directory (ex: /myapp/vendor/) . 3. Bundler 还允许您指定安装 gems 的路径,您可以将它们安装在项目目录中(例如:/myapp/vendor/)

# Per project
bundle config --local path vendor
bundle install
# Saves configuration to /myapp/.bundle/config

# Global
bundle config --global path vendor
bundle install
# Saves configuration to ~/.bundle/config

There could be alternative ways to deal with this, but these are all of the methods I'm familiar with.可能有其他方法来解决这个问题,但这些都是我熟悉的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM