8

What is the exact difference between using:

1- gem install [gemname]

and

2- add gem name & version to GemFile and run bundle install

?

Simple Lime
  • 10,790
  • 2
  • 17
  • 32

1 Answers1

10

RubyGems is akin to a package manager for Ruby. It's a means by which you can install self-contained libraries to use in your applications. When you use gem install gemname you're installing that gem to the current machine that you're developing on.

Bundler is a tool for managing the gems that your application depends on. When you create a Gemfile, you list the various gems and their versions that your application requires. This allows you to easily ensure that your application has the gems it needs when you deploy it to a new location - for example, when you push to Heroku, your Gemfile is used to determine all the dependencies of your application.

Running bundle install will take the list of required gems in your gemfile and install them if they aren't installed already, just like doing gem install for each gem that your application needs.

rayashmanjr
  • 166
  • 1
  • 4
  • Thanks! but I wanted to know if I install all 4example 15 gems using `gem install`, is that the same as putting them in Gemfile and run `bundle install`? I don't think so, because `bundle install` takes too much time with plenty of errors, while `gem install` installs the Gems quickly often without errors! –  Jun 11 '13 at 15:09
  • Hard to say for sure why Bundler is slower without any other details, but Bundler does automatically check for and install newer versions of all dependent gems (even ones you did not explicitly declare, but are dependencies of ones you did declare), which probably makes it slower than `gem install`. – rayashmanjr Jun 11 '13 at 15:32
  • So you say `gem install` for all the gems in GemFile, manually, wont get the app to work? (because of the dependencies)!! –  Jun 11 '13 at 16:04
  • `gem install` will also try to get the dependencies too (with a prompt if I remember correctly, or using `--include-dependencies`). Bundler is just a means of making it easier. Ideally, typing `bundle install` after porting an app to a new environment is easier than doing `gem install` for all your gems. – rayashmanjr Jun 11 '13 at 16:10