ruby bundler
abstract
Bundler is a Ruby gem which installs Ruby gems. Bundler installs a separate bundle
of gems for each software project on a machine. Keeping projects' gems separated helps developers avoid dependency hell.
basics
- Open a terminal and
cd
to a project's top-level folder. - Create a Gemfile listing the project's required gems and version constraints.
- Run
bundle
to install all gems in theGemfile
and their dependencies. - Bundler creates a Gemfile.lock file listing pinned versions of all installed gems.
- Bundler automatically updates Gemfile.lock on subsequent runs.
commands
The rake gem is used here as an example.
gem install bundler |
install Bundler |
gem uninstall bundler |
uninstall Bundler |
gem update bundler |
update Bundler |
bundle clean |
remove unused gems |
bundle exec gem list |
show installed gems |
bundle exec irb |
start interactive Ruby |
bundle exec ruby path/to/script.rb |
run a Ruby script |
bundle init |
create a minimal Gemfile in current folder |
bundle install |
install all gems in Gemfile |
bundle show rake |
show path to rake |
bundle update rake |
update rake |
dependencies
examples
Example Gemfile
file:
ruby '~> 2.3' source 'https://rubygems.org' do gem 'nokogiri' gem 'rails', '3.0.0.beta3' gem 'rack', '>=1.0' gem 'thin', '~>1.1' end
Example .gitignore
file:
.bundle/ # Bundler config files vendor/bundle # Locally-installed gem files
faq
- Where are the official docs?
- Bundler docs
- Bundler workflow
-
Gemfile.lock
reference