What is a gem, and how is it different from a library?
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.
Cite
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.Today's experiment in
colors.rb:require 'json' require 'colorize' puts JSON.generate({ hello: "world" }) puts "done".greenResult:
cannot load such file -- colorize (LoadError)So
jsonloaded without me doing anything, butcolorizedid not. Why was one already there? A friend told me "json is part of Ruby, colorize is a gem", but then I looked atgem listandjsonis 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
requireactually do, and what doesgem installdo? I am on Ruby 3.3 with rbenv, so I would like to stay out of the system Ruby.
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.
4 answers
- Dmitri V.Member ·
Think of it as apt vs. the files apt installs. A gem is the package: name, version, files, metadata.
requireloads one of the files into your running program. Package manager and loader are different tools. Also keep an eye ongem env, it shows where gems land on your machine.