sjain
sjain

Reputation: 23344

Difference between bundle show gemname and gem list gemname

If I do gem list rack-cache in rails command prompt then it shows no gem with that name but if I do bundle show rack-cache then it gives me the path like /vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2 of where the gem is stored.

I didn't understood this behavior because if the gem is present in the path with the latter command then why its not showing when I gives gem list rack-cache command. What's the difference.

Upvotes: 2

Views: 5132

Answers (3)

Tigraine
Tigraine

Reputation: 23648

The confusion comes from the issue bundler is solving.

When you install Gems into your system-wide gem repository you end up with multiple versions of the gem once you have a couple of apps.

So for example you could end up with 3 Rails versions: 3.2.8, 3.2.6 and 3.1.0

If you do a require rails rubygems could use any of these versions and you'll end up with confusion if your App that was initially built against 3.1.0 isn't compatible with some change s in 3.2.8.

What bundler does is install exactly the gems that are specified in the Gemfile.lock and locks those down for the use of that app. Bundler therefore modifies the load-paths for rubygems so only the Gems in the Gemfile.lock are really available to the app.

Therefore bundle install is not installing gems into the system-wide gem directory but rather installs to a different path for each project. That's why you see the gem in a bundler directory and not system wide. If you install rack-cache through gem install you'll also see it in gem list.

Upvotes: 6

vijikumar
vijikumar

Reputation: 1815

bundle show :

Shows all gems that are part of the bundle, or the path to a given gem

$ bundle show [GEM] [--paths]

When in development mode on your mac, the gems still get installed in the default gem path, whereas in production mode, they get installed in a folder specific to your project. Try doing a bundle show rails on each machine and you'll see what I mean.

When you run gem list it looks in the main gem folder, and since your production gems are sitting in a project-specific folder, the global gem command doesn't know to look there. So you will need to do a bundle exec to run any of those project-specific gemscommands on the server. For my purposes, I created a be alias to bundle exec. Also, to list your project's gems, you can do bundle list.

See http://gembundler.com/rationale.html#deploying-your-application for the rationale behind this

Upvotes: 2

Gowri Naidu R
Gowri Naidu R

Reputation: 2034

There is a small difference between bundle show and gem list

bundle show will list all the gems which are installed in your current application[you can see them in Gemfile.lock file],where as gem list will list all the gems installed under any gemset which is set to be using.
bundle show gem_name will give path where it is.
gem list gem_name will give same gem_name with all versions installed into your local gems or gemset.

Upvotes: 2

Related Questions