How to Install Ruby on Debian 10

By 

Published on

4 min read

Install Ruby on Debian

Ruby is one of the most popular languages today. It has an elegant syntax, and it is the language behind the Ruby on Rails framework.

In this article, we will look into different ways to install Ruby on Debian 10.

We’ll show how to install Ruby from the default Debian 10 repositories and using the Rbenv and RVM scripts. Choose the installation method that is most appropriate for your setup and environment.

Install Ruby from Debian Repositories

This is the easiest method for installing Ruby on Debian. At the time of writing, the version in the standard Debian repositories is 2.5.5.

Run the following commands as root or user with sudo privileges to refresh the packages list and install Ruby:

Terminal
sudo apt update
sudo apt install ruby-full

Once the installation is completed, verify it by printing the Ruby version:

Terminal
ruby --version

The output will look something like this:

output
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux-gnu]

Your Ruby version may differ from the one shown above.

That’s it! You have successfully installed Ruby on your Debian system, and you can start using it.

Installing Ruby using Rbenv

Rbenv is a lightweight Ruby version management utility that allows you to easily switch Ruby versions.

We’ll use the ruby-build plugin that extends the core functionality of Rbenv and allow you to install any Ruby version from source.

Start by installing git and other dependencies required to build Ruby from the source:

Terminal
sudo apt update
Terminal
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

Run the following command to install both rbenv and ruby-build scripts:

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

The script will clone both rbenv and ruby-build repositories from GitHub to ~/.rbenv directory.

To start using rbenv, you need to add $HOME/.rbenv/bin to your PATH .

If you are using Bash:

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

If you are using Zsh:

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

Run the rbenv -v command to ensure that installation was successful:

Terminal
rbenv -v
output
rbenv 1.1.2-26-gc6324ff

To get a list of all Ruby versions that can be installed with rbenv enter:

Terminal
rbenv install -l

For example, to install Ruby version 2.7.0 and set it as default version, you would type:

Terminal
rbenv install 2.7.0
rbenv global 2.7.0

Verify that Ruby was properly installed:

Terminal
ruby -v
output
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]

Install Ruby using RVM

RVM (Ruby Version Manager) is a command-line tool that allows you to install, manage, and work with multiple Ruby environments.

Install the dependencies required to build Ruby from source:

Terminal
sudo apt update
Terminal
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

Run the following commands to add the GPG key and install RVM:

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

To start using RVM, enter:

Terminal
source ~/.rvm/scripts/rvm

To get a list of all known Ruby versions type:

Terminal
rvm list known

Install the latest stable version of Ruby with RVM and set it as the default version:

Terminal
rvm install ruby
rvm --default use ruby

Verify that Ruby was properly installed by printing the version number:

Terminal
ruby -v
output
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

If you want to install a specific version of Ruby, enter the commands below. Replace x.x.x with the Ruby version you want to install:

Terminal
rvm install ruby-x.x.x
rvm --default use ruby-x.x.x

For more information about how to manage your Ruby installations with RVM check their Documentation page .

Conclusion

We have shown you three different ways to install Ruby on your Debian 10 server. The method you choose depends on your requirements and preferences. Even though installing the packaged version from the Debian repository is easier, the Rbenv and RVM methods give you more flexibility for adding and removing different Ruby versions on a per user basis.

If you have any questions or feedback, feel free to comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page