Ruby is a dynamic, open-source programming language behind the Ruby on Rails framework. It is especially appealing to beginners because of its highly readable and clear syntax, allowing users to develop fast and efficiently.
In this guide, find three options to install Ruby on Ubuntu 18.04 – either from the Ubuntu repository or from third-party tools (RVM and rbenv).
- Ubuntu 18.04 Bionic Beaver installed and running
- A user with sudo privileges. If necessary, you can create a sudo user on Ubuntu.
- Access to a terminal/command line
- The apt tool, pre-loaded in Ubuntu and other Debian-based distros.
Option 1: Install Ruby from the Ubuntu Repository
To install Ruby from the default Ubuntu repositories, follow these steps:
1. Open the terminal either by using Ctrl+Alt+T keyboard shortcut. Or, by running a search in Ubuntu Dash and typing in the word “terminal“ and selecting the Terminal Icon as seen in the image below.
2. Make sure to update the package repository cache to ensure you install the latest versions of the software.
To do so, type in the following command:
sudo apt update
3. Start the Ruby installation process by running the command:
sudo apt install ruby-full
Press y and hit Enter to verify the installation.
4. To check whether the installation was successful, type in the command:
The output you receive will show you which version of Ruby you have installed, just like in the image below:
As you can see, we have installed Ruby version 2.5.1.
Option 2: Installing Ruby with RVM
Ruby Version Manager (RVM) is a command-line tool which allows you to easily install, manage and work with Ruby versions and their gems.
To enable RVM, you will have to install the GPG keys to verify the installation package.
Step 1: Install GPG
1. Start by running the command:
sudo apt install gnupg
2. Next, install the keys:
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Note: Learn how to delete GPG keys.
Step 2: Install RVM
1. Before installing RVM, you will need to install software prerequisites with the command:
sudo apt install software-properties-common
2. Next, you will add the PPA repository for Ubuntu and finally install RVM.
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt update
sudo apt install rvm
3. At this point, it is recommended to restart your system.
Step 3: Install Ruby
Now that you have set up the RVM command-line, you can install Ruby by typing the following command:
rvm install 2.5.1
2.5.1 is one version of Ruby. You can specify whichever version of Ruby you want to install.
Make sure the installation was successful by checking the version of Ruby you have installed with the command:
Note: If you are running a Windows server, you can refer to How to Install Ruby on Windows 10.
Option 3: Install Ruby Using rbenv
Simple Ruby Version Management (rbenv) is a third-party command tool designed for easier alternation between various Ruby versions. It is specific to switching Ruby versions, making it simple and predictable.
1. Copy the command below to install the packages and dependencies required to build Ruby:
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. To install rbenv and ruby-build, type in the command:
curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -
3. Next, you need to add rbenv to your path with the following three (3) commands:
echo ‘export PATH=”$HOME/ .rbenv/bin:$PATH”’ >> ~/.bashrc
echo ‘eval “$(rbenv init –)”’ >> ~/.bashrc
4. After you have installed rbenv, you can install the latest version of Ruby. Run the command:
rbenv install 2.5.1
5. Make sure the installation was successful by checking the version of Ruby you have installed:
Update Ruby Gems Package Manager
To install, manage and distribute your Ruby libraries (also called gems) you will need the RubyGems package manager.
Each gem contains a Ruby code which you can share with other users. Primarily, these gems serve as libraries from which you can easily install any package required.
The RubyGems management framework is part of Ruby which is why you don’t have to install it separately.
However, you may need to update to the latest version with the command:
gem update --system
Note: There are several ways to install Ruby on an Ubuntu system. To find out more, refer to How to install Ruby on Ubuntu 20.04.
By following one of the three methods above, you will successfully install Ruby on Ubuntu 18.04.
Next, you may want to install a full Ruby on Rails stack. This is one of the most popular application-development stacks in use. Rails is a development framework for the Ruby programming language that simplifies and speeds up app development.