How to Install Ruby

Enter the commands in a terminal without typing the beginning $ sign.

Steps for Installing Ruby

1. Make sure you are using Mac OSX Yosemite (10.10.x) or later, or Windows.

2. Make sure you are logged in with admin privilege.

3. Mac Only: installing Ruby (and numerous other things) becomes easy if you have homebrew installed. To check whether you have it installed, enter the following command:
$ brew --version

If it throws an error, you don't have homebrew. In that case, install homebrew using the following command.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Follow all suggestions that the installation script shows you. 

Optional: You can update your version of homebrew and upgrade all the packages it installed by running the following command.

$ brew update && brew upgrade

4a. Mac: Ruby comes built-in with Mac. This step will install the latest version of Ruby. If you want, you can check the existing version of ruby by entering the following command.

$ ruby --version

In my case, it was 2.6.3p62. Install the latest version of ruby by entering the following command.

$ brew install ruby

It will take a while. After it's done, scroll up and locate and follow all the export and other instructions. 

Example:

If you need to have ruby first in your PATH run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

Copy and run the command echo 'export PATH=... in your terminal. Instead of .zshrc above, you may see something different. Don't change that to .zshrc; just copy the line and paste. Similarly, run the other export commands suggested by the installer.

Exit your terminal by typing: 

$ exit

And then close and reopen the terminal. Check that you have the latest version by entering the following command.

$ ruby --version

In my case, I got the updated version 3.2.2.

4b. Windows: Go to https://rubyinstaller.org/. Click Download and choose the latest version "WITH DEVKIT". Run the downloaded Ruby installer along with the development kit.