Add gem to gemfile with bundler from command line

RubyGemBundler

Ruby Problem Overview


When using node package manager you can specify npm install --save mynodemodule which automatically pops the module in 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?

For example bundle install --save nokogiri

Ruby Solutions


Solution 1 - Ruby

If you visit this question in 2018, bundler now has a cli to do this:

bundle add <gem-name> <version>

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

Solution 2 - Ruby

Just wrote Gemrat to do this.

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

Solution 3 - Ruby

echo 'gem "nokogiri"' >> Gemfile

Solution 4 - Ruby

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

bundle add rails --group "development, test"

More information

bundle add --help

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsrenView Question on Stackoverflow
Solution 1 - RubyzocoiView Answer on Stackoverflow
Solution 2 - RubyDruView Answer on Stackoverflow
Solution 3 - Rubydj2View Answer on Stackoverflow
Solution 4 - RubylesterzoneView Answer on Stackoverflow