ruby 使用 bundler 从命令行将 gem 添加到 gemfile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8005277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 04:27:05  来源:igfitidea点击:

Add gem to gemfile with bundler from command line

rubygembundler

提问by sren

When using node package manager you can specify npm install --save mynodemodulewhich automatically pops the module in package.json

使用节点包管理器时,您可以指定npm install --save mynodemodule哪个自动弹出模块package.json

I was wondering if there is a command for bundler that allows you to add the gem and version to the gemfile from the command line?

我想知道是否有 bundler 命令允许您从命令行将 gem 和版本添加到 gemfile 中?

For example bundle install --save nokogiri

例如 bundle install --save nokogiri

采纳答案by zocoi

If you visit this question in 2018, bundlernow has a cli to do this: bundle add <gem-name> <version>

如果您在 2018 年访问此问题,bundler现在有一个 cli 来执行此操作: bundle add <gem-name> <version>

Version string could be your typical gem version including >=and ~

版本字符串可能是您典型的 gem 版本,包括>=~

回答by Dru

Just wrote Gemratto do this.

刚刚写了Gemrat来做到这一点。

    $ gem install gemrat 
    $ gemrat nokogiri

    #=> gem 'nokogiri', '1.6.0' added to your Gemfile.
    #=> Bundling...

回答by dj2

echo 'gem "nokogiri"' >> Gemfile

回答by lesterzone

as @zocoi described, you can use bundle and specify the group:

正如@zocoi 所述,您可以使用 bundle 并指定组:

bundle add rails --group "development, test"

More information

更多信息

bundle add --help