3 ms·
Bundler basically lets you set up and hop between different "sets" of gems. Say I want to set up a bunch of gems for my new ruby app. I have a Gemfile, and so
by damncabbage 15y ago
Bundler basically lets you set up and hop between different "sets" of gems.
Say I want to set up a bunch of gems for my new ruby app. I have a Gemfile, and so I use Bundler to install those gems for this app only. For example:
~$ cd myapp
~/myapp$ bundle install
# Installs a ton of gems.
Now we can use those gems:
~/myapp$ bundle exec rails console # Or...
~/myapp$ bundle exec rails server # Or...
~/myapp$ bundle exec rake db:migrate
This can get cumbersome, so I usually put this in my .bashrc:
alias be="bundle exec"
# Example usage: be rails console
# Example usage: be rails server
I hope this clears things up a little. (I see RVM being used to manage sets of gems, but Bundler does this out of the box.)
- derwiki 15y agoThanks for the writeup. I've been using bundler for about 6 months (and even have the same 'be' alias!) and understand it, I'm just confused when it seems to magically forget about my installed bundle.
- asolove 15y agoI have run into two reasons why this happens unexpectedly: 1. rvm-related. You installed a gemset for 1.9.2, and then either manually switched to another ruby version, or never set that version as your default. So the next time you come into the project, your ruby version is different and the gemset isn't there. 2. bundler-related: because of other gemsets and your bundler/rvm versions, you need to run commands with the 'bundle exec' prefix (e.g. 'bundle exec rails s') in order to use the context of the current bundle.
- damncabbage 15y agoThe faffing around with RVM gemsets vs Bundler gemsets is why I use rbenv (https://github.com/sstephenson/rbenv https://github.com/sstephenson/rbenv), and use Bundler exclusively to manage gemsets per application. I have a small group of globally-installed gems for convenience when starting new projects (ie. rails). (I'm lucky enough to not work on anything that doesn't use Bundler, fortunately.)