How to install Ruby and Ruby on Rails on Ubuntu 19.04
Tags: rails, linux, server, rvm
Published: 2020-08-15 07:30:29

---
title: How to install Ruby and Ruby on Rails on Ubuntu 19.04
published: true
description: How to install Ruby and Ruby on Rails on an Ubuntu 19.04 x64 server instance using RVM.
tags: rails, Linux, server, rvm
cover_image: https://images.unsplash.com/photo-1549605659-32d82da3a059?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80
---


Ruby on Rails(RoR) is a web framework written in the Ruby programming language, designed to develop successful projects while writing less code.

The command-line tool RVM (Ruby Version Manager) which allows you to install, manage, and work with ruby environments from interpreters to sets of gems.

## Prerequisites

- Ubuntu 19.04 x64 server instance

- we need to install `software-properties-common`:

  ```sh
  sudo apt-get install software-properties-common
  ```

  

## Installation

Run the following command to add the RVM key to your system, this key allows us to verify the legitimacy of the RVM release we will be downloading, which is a sign with the matching private key:

```sh
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
```

### Install and Configure RVM

Let’s now move into a writable location such as the `/tmp` directory:

```sh
cd /tmp
```

Now run the following command to install the latest stable version of RVM:

```sh
curl -sSL https://get.rvm.io | bash -s stable
```

When the installation is complete, source the RVM scripts from the directory they were install, which will be in your `/usr/local/rvm/` directory:

```sh
source /usr/local/rvm/scripts/rvm
```

Now the source for RVM is set. You can check the version number of RVM installed on your system:

```sh
rvm --version
```

Install the latest version of Ruby and Ruby on Rails on your system, First, check to see which version of Ruby are available:

```sh
rvm list known
```

Through this list, install the specific version of Ruby that you need through RVM

> **Note:** In this article, I have installed Ruby 2.6.3 version, you can install a specific Ruby version you need through RVM.

```sh
rvm install 2.6.3
```

After the installation, list available Ruby version we have installed:

```sh
rvm list
```

Run the following RVM command will help you to set the installed version of Ruby as the system default:

```sh
rvm use --default 2.6.3
```

### Install Ruby on Rails

Next, we can install the latest version of _Bundler_ :

```sh
gem install bundler
```

After that, list available versions of Rails:

```sh
gem search '^rails$' --all
```

> **Note:** this RoR version will only refer to the version number.

Now, install Ruby on Rails need version:

```sh
gem install rails -v 5.2.3
```

### Install JavaScript Runtime

We need to install some dependencies of RoR, It is a prerequisite for compiling Ruby on Rails asset pipeline:

```sh
cd /tmp
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -o install_nodejs.sh
```

Verify the Node script by outputting it to a file, then read it with `less`: 

```sh
less install_nodejs.sh
```

If you're satisfied with the Node script, install the Node source Node.js v12.x repo:

```sh
cat /tmp/install_nodejs.sh | sudo -E bash -
```

Next, update apt, and install Node:

```sh
sudo apt update
sudo apt install -y nodejs
```

Install the Yarn package manager:

```sh
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
```

```sh
sudo apt-get update && sudo apt-get install yarn
```