Getting Started
Overview
Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.
Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install.
Install Bundler
Note: You should install ruby first. Recommended: Use rbenv to install and manage different versions of ruby.
Getting started with bundler is easy! Open a terminal window and run this command:
Add Gemfile
GemfileSpecify your dependencies in a Gemfile in your project's root:
bundle install
bundle installInstall all of the required gems from your specified sources:
Warning: If you try to use
bundle install --path vendor/bundle, you will get a warning: [DEPRECATED] The--pathflag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please usebundle config set --local path 'vendor/bundle', and stop using this flag.
Other way to setup the install path for gems:
Setup path for current project only: add
./.bundle/configat the root of the project;Setup path globally: add
~/.bundle/configat user's home directory.
config file sample:
Use gems in code: require
requireInside your App, load up the bundled environment:
bundle exec
bundle execRun an executable that comes with a gem in your bundle:
In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.
However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
Finally, if you want a way to get a shortcut to gems in your bundle:
The executables installed into bin are scoped to the bundle, and will always work.
Create a gem with Bundler: bundle gem
bundle gemBundler is also an easy way to create new gems. Just like you might create a standard Rails project using rails new, you can create a standard gem project with bundle gem.
Create a new gem with a README, .gemspec, Rakefile, directory structure, and all the basic boilerplate you need to describe, test, and publish a gem:
Check Bundler's environment: bundle env
bundle envPrint information about the environment Bundler is running under.
Last updated