bundle install with a Gemfile.lock present?You have a Gemfile and a Gemfile.lock in your Rails project. You run bundle install. What does Bundler do?
Think about how Bundler ensures consistent gem versions across machines.
Bundler uses Gemfile.lock to lock gem versions. When present, bundle install installs exactly those versions to keep consistency.
You want to add the gem pry only for development. Which Gemfile snippet is correct?
Remember the standard way to group gems by environment in Bundler.
The group :development do ... end syntax is the correct way to specify gems for a specific environment. Option D is invalid syntax, C uses a wrong key, and D uses a non-existent group name.
bundle exec rails server fail with 'Could not find gem' error after adding a new gem?You added a new gem to your Gemfile and ran bundle install. But running bundle exec rails server gives an error: 'Could not find gem ...'. What is the likely cause?
Think about how Bundler uses Gemfile.lock to track installed gems.
After adding a gem, running bundle install updates Gemfile.lock only if the gem version is new or missing. Sometimes you need bundle update to update Gemfile.lock and resolve dependencies properly.
source line in a Gemfile?In a Gemfile, you often see a line like source 'https://rubygems.org'. What does this line do?
Think about where gems come from when you run bundle install.
The source line tells Bundler the URL of the gem server to download gems from, usually https://rubygems.org.
Gemfile.lock after running bundle install with this Gemfile?Given this Gemfile:
source 'https://rubygems.org' gem 'rails', '~> 7.0.0' group :development do gem 'pry' end
You run bundle install on a fresh project. What will Gemfile.lock contain regarding the pry gem?
source 'https://rubygems.org' gem 'rails', '~> 7.0.0' group :development do gem 'pry' end
Consider how Bundler groups gems in the lockfile.
Bundler records gems in Gemfile.lock under their respective groups. Gems in group :development appear under the development group section.