Oct 4, 2023 5 min read

How to Install Ruby on Debian 10

Install ruby on debian 10 with our step-by-step tutorial. It is the language that underpins the Ruby on Rails framework and has elegant syntax.

Install Ruby on Debian 10
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking on How to install Ruby on Debian 10. Let’s briefly understand - What is Ruby?

Ruby is one of the most widely used programming languages today. It is the language that underpins the Ruby on Rails framework and has an elegant syntax.

Installing Ruby on Debian 10 opens up a world of possibilities for developers, providing them with a powerful and versatile programming language. Ruby's compatibility with Debian 10 ensures a smooth installation process, allowing developers to leverage its rich library ecosystem and powerful language features.

In this tutorial, we will walk you through the steps to install Ruby on Debian 10, enabling you to harness the full potential of this dynamic programming language.

Install Ruby from Debian Repositories

The simplest technique for installing Ruby on Debian is this one. The version in the standard Debian repositories is 2.5.5, as of the time this article was written.

To update the packages list and install Ruby, run the following commands while logged in as root or as a user with sudo privileges:

sudo apt update
sudo apt install ruby-full

Verify that the installation was successful by printing the Ruby version:

ruby --version

The output will resemble the one shown below:

Output

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

It is possible that your Ruby version differs from the one shown above.

And you are set! Ruby is successfully installed on your Debian system and ready for use.

Installing Ruby using Rbenv

Rbenv is a simple Ruby version management tool that enables you to transition between Ruby versions with ease.

We will be using the ruby-build plugin, which enhances Rbenv's core functionality and allows you to install any Ruby version from the source.

Install git and any other dependencies needed to compile Ruby from the source first:

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

To install the rbenv and ruby-build scripts, issue the following command:

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

Both the rbenv and ruby-build repositories from GitHub will be cloned by the script to the ~/.rbenv directory.

You must add $HOME/.rbenv/bin to your PATH in order to use rbenv.

If you are using Bash, you should:

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

If you are working with Zsh:

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

To check whether the installation was successful, run the rbenv -v command:

rbenv -v
Output

rbenv 1.1.2-26-gc6324ff

Enter the following to acquire a list of all Ruby versions that rbenv can install:

rbenv install -l

For reference, to install Ruby version 2.7.0 and make it the default version, you should enter:

rbenv install 2.7.0
rbenv global 2.7.0

Check to see if Ruby was installed properly:

ruby -v
Output

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

Install Ruby using RVM

A command-line utility called RVM (Ruby Version Manager) enables you to install, manage, and operate with various Ruby environments.

Installing the dependencies required for building 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

To add the GPG key and install RVM, enter the commands below:

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

You can start using RVM by entering:

source ~/.rvm/scripts/rvm

Type the following to generate a list of all known Ruby versions:

rvm list known

Install Ruby's most recent stable version using RVM and make it the default version:

rvm install ruby
rvm --default use ruby

Printing the Ruby version number will show whether it was installed properly:

ruby -v
Output

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

Enter the commands listed below to install a specific version of Ruby. The Ruby version you want to install should be substituted for x.x.x:

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

Visit their Documentation page for more details on managing your Ruby installations using RVM.

Advantages of Installing Ruby on Debian 10

  1. Compatibility: Ruby is natively supported on Debian 10, ensuring easy installation and seamless integration with the operating system.
  2. Vast Library Ecosystem: Installing Ruby enables access to a rich collection of gems and libraries that enhance the development process.
  3. Powerful Language Features: Ruby's elegant syntax, object-oriented nature, and extensive meta programming capabilities enable efficient and expressive coding.
  4. Web Development: Ruby's popular framework, Ruby on Rails, simplifies web development, offering features like MVC architecture and integration with databases.
  5. Community Support: The Ruby community is vibrant, supportive, and continuously contributes to the language, ensuring regular updates, bug fixes, and new features.

FAQs to Install Ruby on Debian 10

How do I update the package list and upgrade existing packages?

Run the commands sudo apt update followed by sudo apt upgrade to update the package list and upgrade existing packages.

How can I install Ruby using apt on Debian 10? 

Use the command sudo apt install ruby-full to install Ruby on Debian 10 using apt.

Is there an alternative way to install Ruby on Debian 10? 

Yes, you can also install Ruby from source using a tool like rbenv.

How can I install rbenv for managing Ruby versions on Debian 10? 

You can use the command curl -sSL https://get.rvm.io | bash -s stable to install rbenv on Debian 10.

How can I add rbenv to the system PATH on Debian 10? 

You can add rbenv to the system PATH by appending the appropriate lines to your shell's profile file.

What is the advantage of installing Ruby using rbenv on Debian 10?

rbenv provides more flexibility in managing different Ruby versions and their associated dependencies.

Are there any prerequisites for installing Ruby on Debian 10?

No significant prerequisites are needed, but it is always a good practice to keep your system updated before installing any software.

Can I install Ruby through a package manager other than apt on Debian 10? 

Yes, you can explore other package managers like rvm, but apt is the recommended method for installing Ruby on Debian 10.

Conclusion

By following the installation steps, including adding the necessary repositories, installing Ruby packages, and verifying the installation, you can harness the power of Ruby's compatibility with Debian 10. The availability of a vast library ecosystem, powerful language features, seamless web development with Ruby on Rails, and vibrant community support make installing Ruby a valuable addition to your Debian 10 system.

Embracing Ruby enables you to develop efficient and expressive applications, leveraging the language's features and benefiting from continuous updates and enhancements driven by the Ruby community.

If you have any doubts regarding this topic, feel free to comment down below, and we'll be glad to help.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.