How to Install Ruby on Debian 10

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:

sudo apt updatesudo apt install ruby-full

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

ruby --version

The output will look something like this:

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:

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

curl -sL https://github.com/rbenv/rbenv-installer/raw/master/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:

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

If you are using Zsh:

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

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

rbenv -v
rbenv 1.1.2-26-gc6324ff

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

rbenv install -l

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

rbenv install 2.7.0rbenv global 2.7.0

Verify that Ruby was properly installed:

ruby -v
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:

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

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

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

To start using RVM, enter:

source ~/.rvm/scripts/rvm

To get a list of all known Ruby versions type:

rvm list known

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

rvm install rubyrvm --default use ruby

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

ruby -v
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:

rvm install ruby-x.x.xrvm --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.