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

Source: https://poignantguide.net/answers/read/what-is-a-gem-and-how-is-it-different-from-a-library/
Site: Poignant Guide Ruby Q&A, category Gems, Bundler and tooling
Published: 2026-12-02. Updated: 2026-12-03. Replies: 4.

## Question by Hugo D., 2026-12-02

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.

Today's experiment in `colors.rb`:

```ruby
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.

## Reply 1 by Sunita R., 2026-12-02

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.

## Reply 2 by Kai N., 2026-12-02

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.

## Reply 3 by Dmitri V., 2026-12-03

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.

## Reply 4 by Farid S., 2026-12-03

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.

---
Cite as: Poignant 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.
