DEV Community

loading...
Cover image for How to install Ruby and Ruby on Rails on Ubuntu 19.04

How to install Ruby and Ruby on Rails on Ubuntu 19.04

Nelson Mfinda
Hey there, I'm Software Developer always up for learning new things and helping along the way. Learning Golang, TDD, CI/CD, Microservice, and Docker.
Updated on ・2 min read

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:

  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:

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:

cd /tmp

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

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:

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:

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:

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.

rvm install 2.6.3

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

rvm list

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

rvm use --default 2.6.3

Install Ruby on Rails

Next, we can install the latest version of Bundler :

gem install bundler

After that, list available versions of Rails:

gem search '^rails$' --all

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

Now, install Ruby on Rails need version:

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:

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:

less install_nodejs.sh

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

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

Next, update apt, and install Node:

sudo apt update
sudo apt install -y nodejs

Install the Yarn package manager:

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
sudo apt-get update && sudo apt-get install yarn

Discussion (0)