如何安装 gem,就像在 Gemfile 中指定的那样?

发布于 2024-12-25 05:34:20 字数 503 浏览 1 评论 0原文

我想通过 gem install 安装 gem,但我需要它来解析当前项目的依赖项。

基本上,当我在 Gemfile 中指定 gem 'xyz' 时,我想要捆绑器提供的功能,但我不想将该特定 gem 添加到 Gemfile 中。

我尝试执行 bundle exec gem install ... 但它似乎不起作用。

编辑:我不想将其添加到 Gemfile 的原因是它可能类似于 metric_fumetricalsaikurorails_best_practices 等。只是实用程序使用的宝石,可能只会让项目变得混乱。

我可能只想暂时使用它们,或者安装它们,尝试一下,如果它不能按照我想要的方式进行 rvm gemsetemptybundle install 再次清理。

I want to install a gem via gem install, but I need it to resolve with dependencies of the current project.

Basically I want the functionality that bundler gives me when I specify gem 'xyz' in a Gemfile, but I don't want to add that specific gem into the Gemfile.

I tried doing bundle exec gem install ... but it doesn't seem to work.

edit: The reason why I don't want to add it to the Gemfile is that it might be something like metric_fu, metrical, saikuro, rails_best_practices, etc. Simply gems that are kind of utility use and might only cluttler the project.

I might only want to use them temporarily, or install them, try out, if it doesn't work out the way I want do rvm gemset empty and bundle install again to clean up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小情绪 2025-01-01 05:34:20

Bundler 的目的部分是为了防止您做类似的事情(当您的项目未声明宝石时,防止您从外部注入宝石)。

寻找一种方法就是在 Bundler 中寻找错误。如果您确实设法找到某种方法来绕过 Bundler 的执行机制,那么您可能不应该使用它;相反,您可以考虑将其作为 Bundler 问题跟踪器的错误提交。

现在我们来讨论真正的问题:你能做什么?你应该做什么?

  • 您应该使用 RVM gemsets 或 Bundler 来隔离您的应用程序及其 gem 依赖项。你不需要两者。为此,我建议使用 Bundler,而不是 RVM gemset。

  • 您应该将您想要使用的以及与您的应用程序集成的任何 gem 添加到 Gemfile 中(即,加载您的应用程序或作为应用程序的一部分加载)。对于任何不与您的应用程序集成的 gem 来说,这不是必需的。

  • 您应该避免将更改后的 Gemfile 或 Gemfile.lock 提交到版本控制,直到您对应用程序继续以可接受的方式运行(测试通过、新 gem 做了一些有用的事情等)感到满意为止。

或者您应该停止使用 Bundler,因为您想做一些它明确设计为阻止您做的事情(不推荐)。

The point of Bundler is, in part, to prevent you from doing things like that (to prevent you from injecting gems from outside when your project doesn't declare them).

Looking for a way of doing that is looking for a bug in Bundler. If you did manage to find some way of skirting Bundler's enforcement mechanisms, you should probably not use it; instead, you may consider filing it as a bug with Bundler's issue tracker.

Now we come to the real questions: what can you do? and what should you do?

  • You should use either RVM gemsets or Bundler to isolate your application and its gem dependencies. You don't need both. I would recommend Bundler for this purpose over RVM gemsets.

  • You should add to your Gemfile any gems that you want to use and that integrate with your application (i.e., that either load your application or that are loaded as part of your application). This is not a requirement for any gems that refrain from integrating with your application.

  • You should refrain from committing a changed Gemfile or Gemfile.lock to version control until you are satisfied that your application continues to operate acceptably (tests pass, new gem does something useful, etc.).

Or you should stop using Bundler, because you want to do things it is explicitly designed to prevent you from doing (not recommended).

离笑几人歌 2025-01-01 05:34:20

冒着听起来很愚蠢的风险,为什么不将它添加到 gemfile 中呢?如果您不想到处安装它,您可以随时将其添加到自己的组中。

At the risk of sounding dumb, why not add it to the gemfile? You can always add it to its own group if you don't want to have to install it everywhere.

逐鹿 2025-01-01 05:34:20

稍微不同的方法是,如果您使用版本控制(例如 Git)来创建新分支并安装 gem。如果不起作用,请卸载 gem(我不确定这将通过旧分支上的捆绑更新来完成)并丢弃该分支。如果确实如此,可以将您的内容合并到旧分支中。

尽管我确实相信其他答案和评论有一些非常好的观点。

A slightly different approach is, if you're using version control, such as Git, to create a new branch and install the gems. If it doesn't work out, uninstall the gem (I'm not sure this will be done by bundle update on the old branch) and trash the branch. If it does, work, merge your stuff into the old the branch.

Though I do believe the other answers and comments have some very good points.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文