Nowadays, Ruby is the most popular language, especially for SaaS application development. It has a perfect and elegant syntax structure, and it is the language behind the ultimate robust framework known as Ruby on Rails.
In this tutorial, we will explain the three different processes to install Ruby on Ubuntu 20.04 machine.
Prerequisites
Before continuing with this tutorial, make sure your system has Ubuntu 20.04 preinstalled and has user access with sudo privileges.
Install Ruby using Ubuntu Repositories
The easiest and state forward way to install ruby on the Ubuntu system is to use an apt package manager with Ubuntu repositories.
You can follow these steps to install Ruby using default Ubuntu repositories:
Step 1 – In the first step, you should update the apt package list using the following command:
$ sudo apt update
Step 2 – After updating the package list, you can install Ruby by using the following command:
$ sudo apt install ruby-full
Step 3 – After the successful installation of Ruby, you can verify it by checking the version of installed Ruby as shown below:
$ ruby --version
You will get the version of installed Ruby on your screen as shown below:
Output:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
Install Ruby using Rbenv
The Rbenv is the Ruby version management system, which helps you switch ruby versions on your system quickly. The Rbenv is not handling the installation process, so you also need to install ruby-build, which is used to install any version of Ruby. It is also available as a plugin for rbenv.
You can install ruby using the rbenv script by following these steps:
Step 1 – In the first step, you should update the package and install the required package for ruby-build to build ruby from source, using the following commands:
$ 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
Step 2 – Now run the below curl command to install ruby-build and rbenv both:
$ curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -
The above script will clone rbenv and ruby-build both repositories from Github to ~/.rbenv directory. This installer script will call one another script, which is use to verify the installation, and the output will come to your screen like below:
Step 3 – include $HOME/.rbenv/bin to the user PATH
If you are using the bash shell, run the below command to include PATH:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc
If you are using the bash shell, run the below command to include PATH:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
$ source ~/.zshrc
Step 4 – Now, you can install any version of Ruby and set it as a default version using the following commands:
$ rbenv install 2.5.1
$ rbenv global 2.5.1
You can list out all available Ruby version using: rbenv install –l
Step 5 – You can verify Ruby has appropriately installed by checking the installed version, as shown below:
$ ruby -v
Output:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Install Ruby using RVM
The RVM is another Ruby version management tool to manage multiple Ruby on a single system, like installing and working with multiple Ruby environments.
To install Ruby using the RVM manager, you should follow these steps:
Step 1 – In the first step, install all dependencies packages and libraries required by RVM to build Ruby from the 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
Step 2 – Now, after resolve, all dependencies install RVM by using the following command:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -sSL https://get.rvm.io | bash -s stable
You can use the following command to use the RVM utility:
$ source ~/.rvm/scripts/rvm
Step 3 – Install Ruby using the RVM management tool using the following command:
$ rvm install 2.5.1
$ rvm use 2.5.1 --default
Now you can verify Ruby installation by checking the version of ruby, as shown below:
$ ruby -v
Output:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
There are multiple option to manage Ruby with RVM; you can follow the official documentation page for RVM (https://rvm.io/).
Conclusion
You have learned three different ways to install Ruby on Ubuntu 20.04 server. You can choose any of these methods to install Ruby as per your requirements and preferences.
If you have any doubts or feedback, feel free to comment below.
The post How to Install Ruby on Ubuntu 20.04 Linux appeared first on Linux Concept.
Discover more from Ubuntu-Server.com
Subscribe to get the latest posts sent to your email.