Free How to Install Ruby on Ubuntu 18:04 – Ruby was one of the most popular programming languages today. It has an elegant syntax and the language behind Ruby on Rails framework is strong. Ruby on Rails has become a top trend for the development of web applications in recent years.

How to install Ubuntu Ruby Rails

Frameworks Ruby-based solution is very comfortable and elegant to create a web site. Therefore, the number of companies that use Ruby on Rails applications is increasing rapidly.

Some well-known web applications created with Ruby on Rails is GitHub, Airbnb, Fiverr, Dribbble, Kickstarter, Crazy Egg and much more. Whether you intend to learn a programming language Ruby on Ubuntu? If yes, please refer to this article.

In this tutorial guide I’ll show you three different ways to install Ruby on the operating system Ubuntu 18:04.

Requirements Install Ruby on Ubuntu

Before starting with this tutorial, make sure you log in as a user with sudo privileges. Read → How to Create User Sudo and Sudo Group in Ubuntu .

1. How to Install Ruby on Ubuntu Repositories

The easiest way to install Ruby on your Ubuntu Linux operating system is via the package manager apt. At time of writing, the version in the Ubuntu repositories is 2.5.1 which is the latest stable version of Ruby.

To install Ruby from the default Ubuntu repositories, follow the steps below:

First, update the package index:

$ sudo apt update

Install Ruby by typing:

$ sudo apt install ruby-full

To verify that the installation was successful run the following command will print version of Ruby:

$ ruby --version

The output will look something like this:

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

2. How to Install Ruby using Rbenv

Rbenv is lightweight Ruby Veris management tool or a lightweight version that allows you to easily switch to a version of Ruby. By default Rbenv not handle the installation version of Ruby so I also need to install ruby-buildwhich is a tool that helps you install the version Ruby whatever you may need. It is available as a standalone program and as a plugin for rbenv.

To install Ruby using scripts Rbenv, follow these steps:

1. First, the index update package and install the necessary package for ruby-build tool to build 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. Next, run the command curlbelow to install rbenv and ruby-build:

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

The script will clone the repository rbenvand ruby-buildfrom GitHub to the directory ~/.rbenv. Scripts to install also call other scripts that will try to verify the installation. Output script would look like this:

how to install ubuntu ruby ​​rbenv

3. Add $HOME/.rbenv/binto the user’s PATH.

If you use the Bash, run:

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

If you are using zsh run:

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

4. Install the latest stable version of Ruby and set as the default version with:

$ rbenv install 2.5.1
$ rbenv global 2.5.1

To create a list of all versions of Ruby available, you can use: rbenv install -l

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

$ ruby -v

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

3. Install Ruby using RVM

RVM is another tool to install, manage and work with some of the Ruby environment.

To install Ruby using RVM script, follow these steps:

1. First install the dependencies needed for the utility 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

2. Run the following command to install RVM:

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

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

$ source ~/.rvm/scripts/rvm

3. Install the latest stable version of Ruby with RVM and set it as the default version with:

$ rvm install 2.5.1
$ rvm use 2.5.1 --default

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

$ ruby -v

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

For more information about how to manage your Ruby installation, visit the Documentation RVM .

Conclusion

I’ve shown you three different ways to install Ruby on your Ubuntu server 18:04. The method you choose depends on your needs and preferences. Although install the package from the Ubuntu repositories easier, Rbenv and methods RVM gives you more flexibility to add and delete different Ruby versions on a per user basis.