Install Ruby and check the version

Install on Linux

On Debian and Ubuntu one package is enough for this course. Update the package list first, then install Ruby.

Other Linux distributions ship Ruby through their own package manager, so the command differs but the result is the same.

Update the package list

sudo apt update

Install Ruby

sudo apt install ruby

The package manager may install a slightly older Ruby than the newest release. That is fine for this course: the examples run on Ruby 3.2 and newer, and a form that only Ruby 3.4 prints is called out where it appears.

The other systems have a page of their own: Ubuntu, Rocky Linux, macOS, FreeBSD, Windows 11, or run Ruby in a container: Docker.

ruby -v

Check what was installed with one short command:

Show the installed Ruby version

ruby -v

Ubuntu 24.04:

ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux-gnu]

Debian 12:

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]

The number depends on the distribution release: Ubuntu 24.04 packages Ruby 3.2, Debian 12 packages 3.1. The lessons were run on Ruby 3.4, and the 3.1 of Debian 12 is too old for the two lessons on Data, because Data.define arrived in 3.2, so a newer Ruby there comes from a version manager. If the terminal answers command not found, the install step above did not finish.

Version managers

Later you may need several Ruby versions on one machine, for example an old project and a new one side by side. Version managers such as rbenv and rvm install Rubies into your home folder and switch between them per project.

You do not need a manager for this course. When you want one, install it from its own documentation first, then it can list and switch the Rubies it manages.

Your first gem command

Ruby ships with a tool called gem that installs shared libraries. Check that it works alongside Ruby:

Show the installed gem version

gem --version

Ubuntu 24.04:

3.4.20

Debian 12:

3.3.15

Later lessons will use gem to add libraries such as test frameworks. For now the version number alone proves that the toolchain is ready.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. Which command installs Ruby from the Debian and Ubuntu package manager?

    Answer

    sudo apt update && sudo apt install ruby

    apt needs the root rights sudo gives, and the package list is updated first.

  2. What does ruby -v print?

    Answer

    The version of the interpreter and the date of its revision

    The line names the version, the revision date and the platform, as ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux-gnu] does.

  3. Which tool installs shared Ruby libraries?

    Answer

    gem

    gem ships with Ruby and installs the libraries the later lessons use.

  4. What is a version manager such as rbenv or rvm for?

    Answer

    It installs several Ruby versions and switches between them per project

    The manager keeps each Ruby in your home folder, and the project chooses one.

  5. The terminal answers command not found after the install. What does the page say it means?

    Answer

    The install step did not finish

    The ruby program is not on PATH, which means the package install did not complete.

  6. A distribution packages Ruby 3.2 while 3.4 is current. What does this lesson say about that?

    Answer

    The examples run on 3.2 and newer, and a 3.4-only form is called out where it appears

    The course targets 3.2 and newer, and the pages that show a 3.4-only form say so.

  7. What does this program print? puts RUBY_VERSION.split(".")[0, 2].join(".")

    Answer

    3.4

    The first two parts of the version string are joined again; the patch level is left out.

  8. Which command checks that the gem tool is installed and prints its version?

    Answer

    gem --version

    gem --version prints one number; gem list prints the installed gems instead.

  9. Which two commands does the page run before ruby -v?

    Answer

    apt update, then apt install ruby

    The package list is refreshed and the ruby package is installed from it.

  10. What is the gem program that ships with Ruby?

    Answer

    The package manager for Ruby libraries

    RubyGems installs and lists libraries; the debugger and the test framework are separate tools.

Article author: Arthur Isaev