Skip to content

Instantly share code, notes, and snippets.

@mdeltito
Last active August 29, 2015 14:04
Show Gist options
  • Save mdeltito/2d9c89b2daebfc636a25 to your computer and use it in GitHub Desktop.
Save mdeltito/2d9c89b2daebfc636a25 to your computer and use it in GitHub Desktop.

Gem a Ruby gem is a package that contains information and files. Cucumber, and RSpec are the gems I currently have.

When I need to install a new gem, I go into my Gemfile in any text editor (Sublime, Vim, etc ;) ) and add the gem and version I want to be used. For example, the latest version of Cucumber is 1.3.16, but I've specified that I want to use 1.2.1. Then I run bundle install to ensure those versions are installed, which also updates my Gemfile.lock

gem list - I can run this command to see a list of local gems, and the versions available

After adding a new gem to my Gemfile, run the following commands:

bundle install - Install the dependencies specified in your Gemfile

rbenv rehash - Through a process called rehashing, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby—irb, gem, rake, rails, ruby, and so on. Shims are lightweight executables that simply pass your command along to rbenv. So with rbenv installed, when you run, say, rake, your operating system will do the following:

  • Search your PATH for an executable file named rake
  • Find the rbenv shim named rake at the beginning of your PATH
  • Run the shim named rake, which in turn passes the command along to rbenv

bundle exec <command> - bundler lets you specify which version of the gem you want to use for your project in the Gemfile. Using bundle exec when running gem commands ensures that the version of the gem from your Gemfile is being used

bundle exec cucumber --version - not necessary to run, but this, for example, will tell you which version of cucumber is running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment