Monday , November 30 2020

How to install Ruby on Debian 9



This tutorial will guide you through the steps of installing Ruby on a Debian 9 system. Today, Ruby is one of the most popular languages. It has an elegant syntax and is the language behind the powerful Ruby on Rails framework.

There are several ways to install Ruby on Debian. In the following sections, we will show you how to install Ruby using the Rbenv and RVM script and the default Debian repositories.

Prerequisites

Before starting the tutorial, make sure you have logged in as user with sudo privileges.

Method 1: Install Ruby from the Debian repositories

The easiest way to install Ruby on your Debian system is through the suitable package manager. At the time of writing this document, the version included in the Debian repositories is 2.3.3 which will soon be created soon.

  1. First, update the package list with:

  2. Install the ruby-full package by running the following command:

    sudo apt installs ruby-full
  3. Once the installation is complete, you can verify that it has succeeded by printing the version of Ruby:

    The output will be similar to this:

    ruby 2.3.3p222 (21/11/2016) [x86_64-linux-gnu]

Method 2: Install Ruby using Rbenv

Rbenv is a lightweight Ruby version management tool that allows you to easily change Ruby versions.

By default, Rbenv does not manage the installation of Ruby versions. ruby-build is a tool that helps you install any version of Ruby that you might need. It is available as a standalone program and as a plugin for rbenv.

  1. Install the dependencies required for the ruby-build tool to create 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
  2. Then, run the following command to install both the rbenv and ruby-build scripts:

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

    In case of successful installation, the script will print something like this:

  3. Before we start using rbenv, we must add $ HOME / .rbenv / bin to our PATH.

    If you use Bash, type:

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

    If you're using the Zsh type:

    echo & # 39; export PATH = "$ HOME / .rbenv / bin: $ PATH" & # 39; >> ~ / .zshrc
    echo & # 39; eval "$ (rbenv init -)" & # 39; >> ~ / .zshrc
    source ~ / .zshrc
  4. Now that rbenv is installed on our system we can easily install the latest stable version of Ruby and set it as the default version with:

    rbenv install 2.5.1
    global rbenv 2.5.1

    Verify that Ruby has been installed correctly by printing the version number:

    ruby 2.5.1p57 (revision 2018-03-29 revision 63029) [x86_64-linux]

Advertisement

Method 3: Install Ruby using RVM

RVM is another tool to install, manage and work with multiple Ruby environments.

  1. First, install the required dependencies for the RVM utility to create Ruby from the source:

    sudo apt update
    sudo apt installs 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
  2. Then, run the following commands to add the GPG key and install RVM:

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

    In case of successful installation, the script will print something like this:

  3. To start using RVM you need to run the following command:

    source ~ / .rvm / scripts / rvm
  4. Install the latest stable version of Ruby with RVM and set it as the default version with:

    rvm installation 2.5.1
    use rvm 2.5.1 - default

    Verify that Ruby has been installed correctly by printing the version number:

    ruby -v
    
    ruby 2.5.1p57 (revision 2018-03-29 revision 63029) [x86_64-linux]

For more information on how to manage your Ruby installations, visit the RVM Documentation page.

Conclusion

We've shown you three different ways to install Ruby on your Debian 9 server. The method you choose depends on your needs and preferences. Although the installation of the version packaged by the Debian repository is simpler, the Rbenv and RVM methods offer more flexibility for adding and removing different versions of Ruby per user.

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


Source link

Leave a Reply

Your email address will not be published.