Opting Out of Installation
If you don’t want to install anything on your computer for some reason, you
can take advantage of cloud-based development environments such as Replit
or GitHub Codespaces. These environments enable you to write your code in
a browser and run it against a cloud-based virtual machine.
Installing Ruby with the rbenv Version Manager
In order to facilitate our installation of Ruby, we are going to use a version manager, which
is a tool that allows you to install and switch between multiple Ruby versions on the same
machine. There are many reasons to use a version manager to handle your Ruby installation.
Being able to easily switch between multiple versions of Ruby gives you the flexibility to
work with multiple projects that might have been written at different times. In addition, the
version managers have been created for easy installation, so installing multiple Ruby versions
with a version manager is easier than installing a single version by itself. More powerful
and easier to use is a hard combination to beat. If you are interested in just downloading
one version of Ruby, you can find system-by-system instructions at
https://www.ruby-lang.org/
en/documentation/installation
.
The tool we are going to use in this book is called rbenv.
4
Rbenv is not the only Ruby version
manager, but it’s probably the most commonly used these days. Other commonly used
version managers are RVM
5
and chruby.
6
(And yes, having competing tools named “RVM”
and “rbenv” is confusing.) If you are using version management for multiple languages,
you might want to look at a project called asdf, which unifies different languages’ version
managers,
7
and is rapidly becoming more popular within Ruby.
We will install rbenv through the conveniently provided rbenv-installer program. If executing
somebody else’s shell script makes you nervous, you can inspect the script at
https://github.com/
rbenv/rbenv-installer/blob/main/bin/rbenv-installer
before you run it.
From a command terminal, enter this command all on one line (the line is split here for page-
width reasons):
$ curl -fsSL
https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Curl is a command-line tool for accessing URLs and doing something useful with the return
value—in this case, retrieving a shell script from the rbenv GitHub repo and passing it along
to a bash shell to be executed.
This script will install rbenv using the appropriate package manager for your system, and
will also install a helper program called ruby-build that will manage the download and
installation of different Ruby versions.
The installation command might produce a lot of output—especially if you are on a macOS
system that uses the Homebrew package manager. On a Mac, it should end with the following,
a Windows user under WSL might see something different:
4.
https://github.com/rbenv/rbenv
5.
https://rvm.io
6.
https://github.com/postmodern/chruby
7.
https://asdf-vm.com
Chapter 1. Getting Started • 4
report erratum • discuss