How to Install Ruby on Ubuntu 18.04?

Photo of author

By admin

Ruby is one of the most popular programming languages among web developers since it is mainly used to create web applications.

Ruby is a general-purpose language with several other applications like prototyping, data analysis, and many more.

The main reason why people prefer Ruby on Ubuntu is that most of the code is written on a Linux server. Ubuntu is the most accessible Linux distribution.

We will show you how to install Ruby on Ubuntu 18.04 in three different ways in this article. They are from Ubuntu Repository and two other third-party tools or websites – RVM and rbenv.

All these methods of installation of Ruby have their own sets of advantages, although nowadays, people prefer using rbenv for installing Ruby.

1. Installing Ruby from Ubuntu Repository

It is pretty easy to install Ruby from the Ubuntu Repository. To install Ruby from Ubuntu Repository, follow these simple steps given below:-

  • Before you install the newest version of Ruby on Ubuntu 18.04, make sure that the package repository cache has been cleared. You can do so by typing in the following command:-

sudo apt update

  • We need to open the Terminal. So, for that, we can either click ctrl + alt + t, keyboard shortcut, or by searching “terminal” in Ubuntu dash, and finally selecting the terminal icon that appeared on the screen.
  • Once the above steps are done, one can proceed with the installation of Ruby on Ubuntu 18.04 by typing in the following command:-

sudo apt install ruby-full

After typing the above command, type y and click the “Enter” button for verifying the installation.

  • To finally verify whether the installation was successful or not, you can type the command:-

ruby –v

  • You will receive an output that will show us the version of the Ruby installed.

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu] So the version downloaded in Ruby 2.5.1

2. Installing Ruby with RVM

Also known as Ruby Version Manager, RVM is a command-line tool for managing, installing, and using Ruby versions when performing work. Firstly, we have to install GPG before installing Ruby from RVM. Then we proceed as follows:-

a. Installing GPG

  • To install GPG, one first needs to run the following command:-

sudo apt install GnuPG

  • Then, we need to install keys using the following code:-

gpg –keyserver hkp://pool.sks-keyservers.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BD

b. Installing Software Prerequisites

  • Enter the following command to install software prerequisites:-

sudo apt install software-properties-common

  • After this, one also needs to add a PPA repository for running Ruby on Ubuntu:-

sudo apt-add-repository -y ppa:rael-gc/rvm

iii. Finally, to install RVM using the following two codes:-

sudo apt update

sudo apt install rpm

  • After doing the above steps, it is advisable to restart your device for the smooth working of Ruby.

c. Installing Ruby

Once the command line – RVM is successfully installed, one can install Ruby by a single code.

rvm install 2.5.1

One can download any version by changing the performance in the above code. For this instance, after installing Ruby version 2.5.1, use the below given command to check the installed version of the Ruby:-

ruby –v

You will receive an output that will show us the version of the Ruby installed.

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

So the version downloaded in Ruby 2.5.1

3. Installing Ruby with the help of rbenv

Ruby Version Management or simply rbenv is a third-party tool that allows us to switch between various versions of Ruby quickly and simply. It is not possible to directly install Ruby from the default rbenv, so one needs to install ruby-build. Simply put, Ruby is a plugin that works with rbenv build, a tool that helps us install any version of Ruby. To install Ruby using the following steps:-

a. So, first of all, we need to install and update specific packages that are essential for the proper functioning of the ruby-build tool: –

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

b. To install rbenv and ruby-build, one has to type the following command:-

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

The above code helps to create a copy of both rbenv and ruby-build repositories from Github.

c. After this, we need to add the following code to the user Path

$HOME/.rbenv/bin

d. Depending upon which shell or command language interpreter you use, you need to type the following codes:-

  • If your shell or command language interpreter is BASH, then type in:-

echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc

echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc

source ~/.bashrc

  • If your shell or command language interpreter is Zsh, then type in:-

echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.zshrc

echo ‘eval “$(rbenv init -)”‘ >> ~/.zshrc

source ~/.zshrc

e. To install the latest version of Ruby and to make it the default version type the following code:-

rbenv install 2.5.1

rbenv global 2.5.1

Now, you need to verify whether you have appropriately installed Ruby by checking the version of Ruby installed:-

ruby –v

You will receive an output that will show us the version of the Ruby installed.

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

So the version downloaded in Ruby 2.5.1

Update Ruby Gems Package Manager

Ruby libraries can be installed and managed with Ruby Gems package manager. Ruby Gems contain Ruby code that can be shared. Ruby Gems are primarily used as libraries, which help us install any package of our choice. For that, one should update Ruby using the following code:-

gem update –system

Installing Ruby on Rails

One may want to install a complete Ruby on Rails stack. App development stacks are the most widely used. Rails is the development framework for Ruby program language, which facilitates app development the quickest way possible.

gem install rails -v 6.1.3.2

If you’re using rbenv, you’ll need to run the following command to make the rails executable available:

rbenv rehash

Now that you’ve installed Rails, you can run the rails -v command to make sure you have everything installed correctly:

rails -v

# Rails 6.1.3.2

There are three different ways by which you can install Ruby on your Ubuntu 18.04 server, with each having its pros and cons. So, installing Ruby using any of the above methods depends entirely on you.

You might have understood that installing Ruby from the Ubuntu repository is comparatively easy. On the other hand, using third-party tools like rbenv and RVM helps install and uninstall the various versions of Ruby quite efficiently and quickly.

To enjoy all the features of Ruby efficiently, it is recommended to use the newest version and updates of the same. As many new updates and technology are coming up daily, it’s crucial to update rbenv so that Ruby runs efficiently.

One can do this by simply using the git pull command:

cd ~/.rbenv

git pull

If you are using a third-party tool then simply install the tool and make the required settings using the code. Then install Ruby and check whether you have successfully installed Ruby on Ubuntu 18.04 server.

Conclusion

There are three different ways by which you can install Ruby on Ubuntu 18.04 server, with each having its pros and cons. Ruby being a popular programming language for web development and other uses is very important to download. Therefore, you can install Ruby on Ubuntu using any of the methods described above. The method you choose to use to install Ruby is entirely up to you.

Ruby can be easily installed in Ubuntu using the repository, but third-party tools such as rbenv and RVM can be used to efficiently and reliably install and uninstall the various Ruby versions. If you prefer to use all the available features of Ruby, it would be a good idea to download the latest version of it. If the above steps are followed properly, installing Ruby on Ubuntu 18.04 server is very easy.

Leave a Comment