How to Install Ruby on Debian 10

Install Ruby on Debian

Ruby is one of the most popular dynamic and powerful programming languages. Ruby can be used for the development of web applications, games etc. It is mostly used for server-side scripting. It was found in 1993 in Japan. In this tutorial, you are going to learn How to install Ruby on Debian 10.

There are two ways to install Ruby on Debian and they are:

  1. Install Ruby using Rbenv (recommended)
  2. Install Ruby using Debian Repository

Prerequisites

Before you start to install Redis on Debian 10. You must have a non-root user account on your server with sudo privileges.

Method 1: Install Ruby using Rbenv

Rbenv is nothing but Ruby version management tool. It is used for switching versions on the same system if multiple versions are installed. To actually Install Ruby we are using here Rbenv plugin ruby-build which is used to install any version easily. Follow the instruction below to install Ruby using Rbenv:

Now Update the apt package manager index by typing below command:

sudo apt update

Install required dependencies for installing rbenv and ruby-build:

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

Navigate to $HOME directory using below command:

cd

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

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 in the terminal one by one:

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

Here to 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"' >> ~/.bashrcCopy
exec $SHELL

The current latest stable version for Ruby is 2.6.1 at the time of writing this tutorial. Run below command to install Ruby:

rbenv install 2.6.1

Now set the global version on your system running following command using terminal:

rbenv global 2.6.1

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

ruby -v

The output should be following:

ruby 2.6.1 [x86_64-linux-gnu]

Method 2: Install Ruby from Debian Repository

Update the package manager index typing below command in terminal:

sudo apt update

Install the Ruby typing following command in terminal:

sudo apt install ruby-full

Confirm the installation and check the version using below command:

ruby -v

The output should be following:

ruby 2.6.1 [x86_64-linux-gnu]

Running a Simple Ruby Program

Now create and open demo.rb example file using your favourite text editor:

sudo nano demo.rb

Copy and paste the following lines inside demo.rb file:

puts "Welcome to Ruby"

Save the file and exit the editor using Ctrl+x.

Next run following command and run demo.rb file:

ruby demo.rb

The output should be following:

Welcome to Ruby

Conclusion

You have successfully learned how to install Ruby on Debian 10. If you have any queries please don’t forget to comment out.

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注