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:
- An operating-system package manager. Homebrew on macOS,
apton Debian and Ubuntu,dnfon 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- A dedicated installer. Tools such as
ruby-buildandruby-installdownload 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- 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 runThe 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.
Check what is there
ruby -vshows 2.6, andwhich rubyshows/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.
Why should you avoid installing gems into the macOS system Ruby?
Which command tells you which Ruby binary your shell will run?
What is RubyInstaller?
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 -vandwhich ruby.
