Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language. According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.

In this guide, we will explain how to install Ruby on a Debian 9 server.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can quickly deploy your cloud servers.

Once you have signed up, log into your Cloudwafer Client Area and deploy your Cloudwafer cloud server.

Updating System Packages

It is recommended that you update the system to the latest packages before beginning any major installations. Issue the command below:

sudo apt-get update && sudo apt-get upgrade

We will be using two methods of installing Ruby on Debian 9:

  • Installing Ruby from the APT package manager.
  • Installing Ruby using Rbenv.

Installing Ruby from the APT package manager
This method of installing Ruby would most likely not provide the latest version of Ruby. As at the time of writing this guide, the release is 2.3.

Issue the command below to install the ruby package:

sudo apt install ruby-full

After installation, issue the command below to check the version:

ruby --version

Installing Ruby using Rbenv
Rbenv is a lightweight Ruby version management utility which allows you to switch Ruby versions easily.

Issue the command below to install the following dependencies which are required by the ruby-build tool:

sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

Next, issue the following curl command to install both rbenv and ruby-build:

curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

Next, add $HOME/.rbenv/bin to our PATH by issuing the following commands:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

To list all available Ruby versions issue the command below:

rbenv install -l

You can now install the latest stable version of Ruby and set it as our default version with:

rbenv install 2.7.0
rbenv global 2.7.0

After installation, issue the command below to check the version:

ruby --version