Where are gem installs coming from?

Viewed 48

I am wondering, while I'm sifting through samples, how I locate the source library when installing gems. For example, I have

require 'oauth2'

and to install, I run

gem install oauth2

What repository is pulled from for gem installs? I want to use reflection to reverse engineer some of the calls in the samples.

2 Answers

By default gem pulls from Rubygems, the main gem repository, but you can install from anywhere if you give it a URL or use the --source option to specify an alternate source. Some prefer to use private gem hosting for their dependencies.

Why not use a Gemfile to manage your dependencies? It makes it a lot more clear:

source 'https://rubygems.org/'

gem 'oauth2'

Then you install:

bundle install

Then you can see where it got installed:

bundle show oauth2

From there you can look at the source. You can also look at the gem listing page for oauth2 where links to documentation and source are provided.

There are a few useful options for looking at source code for ruby gems. As @tadman has mentioned you generally can expect the default gem source to be hosted at https://rubygems.org and using Bundler is also highly recommended.

In many cases the open source code will be hosted on https://github.com. I tend to prefer to fork the gem source and download my fork locally where I can analyze it in my editor without fear of accidentally breaking anything since your forked repo will contain the full git history/repo etc.

If you're new to ruby, I would highly recommend you use a ruby version manager, i.e. RVM or perhaps RBENV, although I tend to find RVM a bit simpler and less problematic.

My other personal favorite ruby code hacking/inspecting tool is PRY

Related