Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction and Setup  ›  Lesson

Package Managers and Installers

Package Managers 12 minLeave the operating system's own Ruby alone and install a current Ruby with a package manager or a dedicated installer, then check which one your shell runs.

Package Managers and Installers

You sit down to write the Bean Cart sales script, type ruby -v, and see a version from years ago, or "command not found". Before any code, you need a working, current Ruby. There are a few ways to get one, and picking the right one saves hours of confusion later.

The rule

Leave the system Ruby alone; install your own current Ruby.

Some operating systems include a copy of Ruby that their own tools rely on. On macOS it is old and marked as deprecated. If you install gems into it or try to upgrade it, you can break things or hit permission errors. So you add a Ruby of your own instead. You have three broad options:

  1. An operating-system package manager. Homebrew on macOS, apt on Debian and Ubuntu, dnf on Fedora. One command, and you get whatever version that package manager currently offers.
brew install ruby        # macOS with Homebrew
sudo apt install ruby-full   # Ubuntu or Debian
  1. A dedicated installer. Tools such as ruby-build and ruby-install download the Ruby source and compile the exact version you ask for. On Windows, RubyInstaller is the standard download, and its "with Devkit" build includes the compiler tools that some gems need.
ruby-install ruby 3.3.5
  1. A version manager, which usually uses an installer behind the scenes and lets you keep several versions side by side. That is the next lesson.

Whichever you choose, check the result:

ruby -v    # prints something like: ruby 3.3.5 (...) [arm64-darwin23]
which ruby # shows which ruby binary your shell will actually run

The shortcut

Ask one question: "Will I ever need two different Ruby versions?" If you only need one current Ruby for learning and small scripts, a package manager is enough. If you will work on projects that each pin their own version, go straight to an installer plus a version manager.

Getting Ruby for Bean Cart on a MacStep 1 of 4
  1. Check what is there

    ruby -v shows 2.6, and which ruby shows /usr/bin/ruby. That is the system Ruby, so leave it alone.

The classic trap is installing Ruby and still running the old one, because your shell finds the system binary first in its PATH. which ruby catches that in one second. Homebrew prints the line to add to your shell profile; follow it.

Drills

Answer fast — trust the rule.

quick drill

Why should you avoid installing gems into the macOS system Ruby?

quick drill

Which command tells you which Ruby binary your shell will run?

quick drill

What is RubyInstaller?

quick drill

You installed Ruby 3.3 with Homebrew, but ruby -v still shows 2.6. What is the most likely cause?

Remember

  • Leave the system Ruby alone; install your own current Ruby.
  • One version needed: a package manager is fine. Several: an installer plus a version manager.
  • Trap: the old Ruby still wins in your PATH; check with ruby -v and which ruby.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy not the system Ruby?

A friend on a Mac runs sudo gem install against the Ruby that came with the system. Explain why that is a bad idea, what they should do instead, and how they can check that the new Ruby is the one being used.