Jwan622
Jwan622

Reputation: 11639

Bundle show. Where are gems installed when I run bundle install? Are they just on my Ruby?

So I'm curious where my devise gem is installed so I can do some source code diving on devise. This led me to ask where the gems are installed when you run bundle install.

So when I run this in my rails app directory:

bundle show

Gems included by the bundle:
  * Ascii85 (1.0.2)
  * CFPropertyList (2.3.2)
  * aasm (4.3.0)
  * actionmailer (3.2.22.2)
  * actionpack (3.2.22.2)
  * active_model_serializers (0.8.1)
  * activeadmin (1.0.0.pre2)
  * activemodel (3.2.22.2)
  * activerecord (3.2.22.2)
  * activeresource (3.2.22.2)
  * activesupport (3.2.22.2)
  * activeuuid (0.5.0)
  * acts-as-taggable-on (3.5.0)
  * acts_as_tree (2.2.0)
...
  * devise (3.5.4)

When I run:

bundle show devise

/Users/jeffrey.wan/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/devise-3.5.4

What is that path? Where does it come from?

Also, more important question, does this mean that all gems when you run bundle install really jsut get installed on your Ruby?

What are the numbers 2.1.6 and 2.1.0?

Upvotes: 0

Views: 1153

Answers (1)

max pleaner
max pleaner

Reputation: 26758

Gem installations will be namespaced by the Ruby version. So if you're using Rbenv or RVM and have a few different Ruby versions installed, running gem install will only install the gem for the version of Ruby you have currently selected.

To respond to your comment, there is no alternative to installing a gem locally if you want to use it. "Locally" meaning "on your computer".

To answer your question about the path:

/Users/jeffrey.wan/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/devise-3.5.4
  1. You are using rbenv, so all your ruby installations are namespaced in the ~/.rbenv directory.
  2. You are currently using ruby version 2.1.6, so your gems are being installed to that folder
  3. To explain the 2.1.0 folder - basically when gems are published, they are pinpointed to a specific Ruby version. So when you request the devise gem be installed to your ruby 2.1.6, the closest matching devise is chosen (in this case, the one build for ruby 2.1.0).

By the way, it can sometimes be useful to use bundle show when you want to debug a gem you've installed. You can go into the source code and add a breakpoint. It's not something I recommend doing often, but can help when you're messing with old, partially-functional gems.

By the way, when you that gems are installed "on your Ruby", that's maybe not the best wording. Installing a gem doesn't patch the Ruby language. All it does is install a library that you can choose to include in your programs (via require). Some gems do create shell commands, too (something like rake, for example).

Upvotes: 1

Related Questions