TIL You can use bundle add to install a gem and add it to the Gemfile

John Gallagher posted on October 6th, 2020

I’ve wanted a one-line way of adding a gem to a Gemfile.

Today I learned you can do:

bundle add sass-rails

Boom. It installs sass-rails to the Gemfile and does a bundle all in one.

What else can you do?

A few other examples from the docs:

bundle add rails

bundle add rails --version "< 3.0, > 1.1"

bundle add rails --version "~> 5.0.0" --source "https://gems.example.com" --group "development"

bundle add rails --skip-install

bundle add rails --group "development, test"

bundle add sass-rails --strict

bundle add sass-rails --optimistic

Which version of bundler?

Introduced in 1.15.

I’m off to save time and hassle with every new gem I add.

Enjoy!

What did you learn today?

Write a quick TIL post to reflect on what you've learned.

Write a post