Author avatar

Ashutosh Singh

How to Set Up a Ruby Development Environment

Ashutosh Singh

  • Aug 11, 2020
  • 8 Min read
  • 12,652 Views
  • Aug 11, 2020
  • 8 Min read
  • 12,652 Views
Web Development
Back End Web Development
Server-side Frameworks
Ruby on Rails

Introduction

First released in the mid-1990s by Yukihiro Matsumoto, the Ruby programming language saw an exponential rise in popularity with the release of Ruby on Rails, a web app framework. Platforms like Twitter, GitHub, Shopify, and others were initially built with RoR (Ruby on Rails).

In this guide, we will set up a Ruby Development Environment on Windows, Ubuntu, and macOS. We will discuss the step-by-step process of downloading, installing, and configuring the environment. We will also discuss RVM, a popular version manager for Ruby, which gives you more flexibility in adding and removing Ruby versions.

Installing on Windows

RubyInstaller is a widely used tool for installing Ruby on Windows. Alternatively, you can also use a package manager like Chocolatey to install Ruby.

Here are the steps to install Ruby with RubyInstaller:

  1. Download the recommended stable version of Ruby+Devkit from https://rubyinstaller.org/downloads/. It will automatically suggest the version most people are using at the time of downloading. Currently, the arrow is pointing at 2.6.6-1. The Devkit versions install the MSYS2 system, which is necessary to install RubyGems that require compilation.

RubyInstaller

  1. Once downloaded, open the installer, check I accept the License, and click Next.

Accept the License

  1. Using RubyInstaller saves you from manually setting the PATH variable and other configurations that you may need. You can change the Ruby installation folder or leave it at default.

Configure

  1. Make sure to check the MSYS2 development toolchain option on the next screen:

MSY2

  1. On the installer's final screen, another checkbox appears: Run ‘ridk install’ to set up MSYS2 and development toolchain. Make sure to select it and click Finish.

Final Screen

Installing Development Toolchain

A terminal window will open to install the development toolchain:

Toolchain

The ridk install command will ask for the components you want to install. Leave it at default, and hit ENTER. After the installation completes, you should see the message, Install MSYS2 and MINGW development toolchain succeeded. You will again see the same install prompt. Just hit ENTER and the terminal will close.

1Install MSYS2 and MINGW development toolchain succeeded
2  
3 1 - MSYS2 base installation
4 2 - MSYS2 system update (optional)
5 3 - MSYS2 and MINGW development toolchain
6
7Which components shall be installed? If unsure press ENTER []
Terminal

Verifying the Installation

You can verify the installation by running the following command in your terminal.

1ruby -v
Terminal

You should see an output like this.

1ruby 2.6.6p146 (2020-03-31 revision 67876) [x64-mingw32]
Output

Installing on Ubuntu

The most common and easiest way to install Ruby on Ubuntu is through the apt package manager, and you can do so with one command. It might be a good idea to update the packages index beforehand.

1sudo apt update
2sudo apt-get install ruby-full
bash

You can verify the installation by checking the version of the Ruby installed.

1ruby --version
bash

Installing on MacOS

Ruby comes pre-installed with default macOS installation; you can check that by running the following command in the terminal.

1ruby -v
terminal

It is possible that the Ruby that came pre-installed is not the most recent version, and you may run into compatibility issues when building projects.

Installing Using Homebrew

You can install Ruby using Homebrew with just one command. In your terminal, run the following command:

1 brew install ruby
terminal

This command will install the most recent stable version of Ruby that is available.

Updating using Homebrew

To update your version of Ruby, get the latest packages by updating Homebrew, and then upgrade Ruby:

1brew update
2brew upgrade ruby
terminal

Installing Ruby with RVM

For most projects, the above installation methods work great. Still, there may come a time when you need to deploy a different implementation of Ruby or a conflict between gems in different projects arises. Installing different versions of Ruby using the above methods can be a real headache. To solve this problem, different version managers like RVM, chruby, rbenv, and others were developed.

RVM (Ruby Version Manager), created by Wayne E. Seguin, is a command-line tool to install, manage, and work with multiple Ruby environments from interpreters to sets of gems. RVM supports most UNIX-like systems, and hence is widely used with Ubuntu. For Windows, you can use WSL(Windows Subsystem for Linux).

Before installing RVM, you need GPG, curl, and bash, but RVM will most likely autodetect it and install anything required.

Installing RVM

To install RVM, run the following commands:

1gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
2curl -sSL https://get.rvm.io | bash -s stable
bash

You need to run the following command to start using RVM:

1source ~/.rvm/scripts/rvm
bash

Installing Ruby with RVM

To install the latest version of Ruby:

1rvm install ruby
bash

Use the latest version as default.

1rvm --default use ruby
bash

To install a specific version of Ruby:

1rvm install X.X.X
bash

Where X.X.X is the version of Ruby.

Using Different Versions of Ruby

You can jump between different versions using the rvm use X.X.X command.

This example will show how to install two different versions of Ruby and switch between them. The same steps can be followed for any number of Ruby versions.

To install and use Ruby 2.5.1, run the following commands:

1rvm install 2.5.1
2rvm use 2.5.1
3ruby -v
bash

Here is the output of the above command:

1ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Output

Now, install a different version of Ruby:

1rvm install 2.1
2rvm use 2.1
3ruby -v 
bash

This Ruby version is different from the above output.

1ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
Output

Both Ruby versions are installed and present in the system simultaneously, and the rvm use X.X.X command specifies which version to use. To see the current version of Ruby, enter the following into the terminal:

1rvm list
bash
1ruby-2.5.1 [ x86_64 ]
2* ruby-2.7.1 [ x86_64 ]
3=>ruby-2.1.1
4
5# => - current
6# =* - current && default
7# *  - default
Output

Uninstalling a Ruby Version

To uninstall any version of Ruby you previously installed using RVM, run the following command:

1rvm uninstall 2.1.1
bash

You can read more about this here.

Conclusion

Now that your local machine is ready for Ruby software development, you can learn more about programming with Ruby and start creating awesome stuff.

Although only RVM was discussed in this guide, many version managers are available out there. You can explore them and find the one that corresponds with your needs. You can also further install and learn Ruby on Rails and take your development to the next level.

Here are some resources you may find useful:

Happy Coding!