Intro to Gems

Gems are one of the best parts of Ruby development. Ruby offers the basic language and functionality to make your application, then anyone in the community can build on that foundation to do more specialized or complex things. When they build something that might be generally useful they can wrap all of that functionality up into a ‘gem’ or a library that you can add to your project. And there’s thousands of them. Which makes it fast, effective and quick to build in cool stuff into your project. For example:

  • sinatra itself is a gem. It adds the functionality to make a basic web application into the basic ruby environment
  • json is another useful gem. It lets you quickly convert JSON strings into native objects in Ruby and vice versa
  • The functionality to make calls to Twitter, Instagram, Facebook and more are offered in multiple gems. This makes connecting to other web services a breeze.

Anyone in the community can add to or extend Ruby’s base functionality with a gem. And this extensibility is a really powerful part of the platform.

There’s a few ways to add gems to your project. The easiest is with bundler. To add that gem to your system type

gem install bundler

You should only need to do that once.

Then in your project folder, create a file called Gemfile (with no extension). Start it with the following line then add a list of gems you want to use.

source ''

gem 'sinatra'
gem 'json'

After you create it or make any changes to it, update and install the gems for your project by typing the following at the command prompt

bundle install




The latest tutorials sent straight to your inbox.