How to Install Ruby on Debian 10

Install Ruby on Debian 10

In this article, we will have explained the necessary steps to install and configure Ruby on Debian 10. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Ruby is a dynamic, object-oriented programming language focused on simplicity and productivity. RVM (Ruby Version Manager) is a tool for installing and managing multiple Ruby versions on single operating systems.

Install Ruby on Debian

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade

Step 2. Install Ruby.

  • Install Ruby from Debian Repository.

Start the Ruby installation process by running the command:

sudo apt install ruby-full

Confirm the installation and check the version using below command:

ruby -v
  • Install Ruby using RVM.

First install the dependencies required for the RVM utility to build Ruby from source:

sudo apt update
sudo apt install curl g++ gcc autoconf automake bison libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev

Next, run the following commands to add the GPG key and install RVM:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
  • Install Ruby using Rbenv.

Install required dependencies for installing rbenv and ruby-build:

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

Next, clone rbenv package typing following command in the terminal:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv

After completing the above command, Set the path for rbenv and complete the installation by typing below commands:

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

Then, install ruby-build plugin for Rbenv run below git command first:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

After completing above command, Complete the installation and set the path for ruby-build by using below command:

echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

You should confirm the installation and check the version of Ruby using below command:

ruby -v

Congratulation, you have learned how to install and configure Ruby on Debian 10 Buster. If you have any question, please leave a comment below.