Skip to content
Poignant Guide Ruby Q&A

What is a gem, and how is it different from a library?

Asked by Hugo D. · Gems, Bundler and tooling4 repliesupdated

Short answer

Apologies in advance, I am likely mixing up words. Every tutorial I read says "install the gem", "use the library", "require the file", and I cannot tell if these are one thing with three names or three things.

Written by Hugo D. ·
CitePoignant Guide Ruby Q&A, "What is a gem, and how is it different from a library?", https://poignantguide.net/answers/read/what-is-a-gem-and-how-is-it-different-from-a-library/, accessed 2026-12-04.
  1. Member ·

    Today's experiment in colors.rb:

    require 'json'
    require 'colorize'
    
    puts JSON.generate({ hello: "world" })
    puts "done".green
    

    Result:

    cannot load such file -- colorize (LoadError)
    

    So json loaded without me doing anything, but colorize did not. Why was one already there? A friend told me "json is part of Ruby, colorize is a gem", but then I looked at gem list and json is in that list too. Attempt number 3 of understanding this, and I am more confused than at attempt 1.

    Is a gem a kind of library? Is a library always a gem? What does require actually do, and what does gem install do? I am on Ruby 3.3 with rbenv, so I would like to stay out of the system Ruby.

    0
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Dmitri V.Member ·

    Think of it as apt vs. the files apt installs. A gem is the package: name, version, files, metadata. require loads one of the files into your running program. Package manager and loader are different tools. Also keep an eye on gem env, it shows where gems land on your machine.

  2. Sunita R.Member ·

    The closest Python picture I have: a library is the code you import, a gem is the package you pip install to get it, and rubygems.org plays the role of PyPI. The analogy is not perfect, but it got me started.

  3. Kai N.Member ·

    Library and gem are the same thing, different words. Run gem install colorize and move on, it fixes the LoadError. I have never needed to think about the difference in nine months of agency work.

  4. Farid S.Member ·

    Careful about one thing: once you have a project with a Gemfile, Bundler decides which gems and versions your code can load. require then only finds what the Gemfile lists. Plenty of "works in irb, fails in my app" tickets come from that.

Poignant Guide Ruby Q&A. Questions and answers on learning Ruby and programming: syntax, blocks, objects, gems, Rails, debugging and reading the Poignant Guide.