image

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

In the tutorial, we will look at different ways to install Ruby on Debian 10.

We will show how to install Ruby from the default Debian 10 repository as well as using Rbenv and RVM scripts. Choose the installation method that best suits your setup and environment.

Installing Ruby from Debian Repository

This is the easiest way to install Ruby on Debian. At the time of writing, the version in the standard Debian repository is 2.5.5.

Run the following command as root user or as a user with sudo privileges to refresh the package list and install Ruby.

1
2
sudo apt update
sudo apt install ruby-full

After the installation is complete, verify by printing the Ruby version

1
ruby --version

The output will look like this.

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

Your version of Ruby may be different from the version shown above.

You have successfully installed Ruby on your Debian system and you are ready to start using it.

Installing Ruby with Rbenv

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

We will use the ruby-build plugin to extend the core functionality of Rbenv and allow you to install any Ruby version from source.

Start by installing git and other dependencies needed to build Ruby from source.

1
sudo apt update
1
2
3
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 the rbenv and ruby-build scripts.

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

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

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

If you are using Bash.

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

If you are using Zsh.

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

Run the rbenv -v command to ensure a successful installation.

1
rbenv -v
1
rbenv 1.1.2-26-gc6324ff

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

1
rbenv install -l

For example, to install Ruby version 2.7.0 and set it as the default version, enter.

1
rbenv install 2.7.0

Verify that Ruby is properly installed.

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

Installing Ruby with RVM

RVM (Ruby Version Manager) is a command line tool that lets you install, manage and use multiple Ruby environments.

To install the dependencies required to build Ruby from source code.

1
sudo apt update
1
2
3
4
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 command to add a GPG key and install RVM.

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

To get started with RVM, enter.

1
source ~/.rvm/scripts/rvm

To get a list of all known Ruby versions, enter.

1
rvm list known

To install the latest stable version of Ruby using RVM and set it as the default version.

1
rvm install ruby

Verify that Ruby is correctly installed by printing the version number.

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

To install a specific version of Ruby, enter the following command. Replace x.x.x with the version of Ruby you want to install.

1
rvm install ruby-x.x.x

For more information on how to use RVM to manage Ruby installations, see its documentation page.

Conclusion

We have shown you three ways to install Ruby on a Debian 10 server. The method you choose depends on your requirements and preferences. While it is easier to install packaged versions from the Debian repository, the Rbenv and RVM methods give you more flexibility to add and remove different Ruby versions on a per-user basis