DEV Community

Cover image for How to install Ruby and Ruby on Rails on Ubuntu 19.04
Nelson Mfinda
Nelson Mfinda

Posted on • Updated on

How to install Ruby and Ruby on Rails on Ubuntu 19.04

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install and Configure RVM

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

cd /tmp
Enter fullscreen mode Exit fullscreen mode

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

curl -sSL https://get.rvm.io | bash -s stable
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

rvm --version
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

rvm list
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install Ruby on Rails

Next, we can install the latest version of Bundler :

gem install bundler
Enter fullscreen mode Exit fullscreen mode

After that, list available versions of Rails:

gem search '^rails$' --all
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

less install_nodejs.sh
Enter fullscreen mode Exit fullscreen mode

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 -
Enter fullscreen mode Exit fullscreen mode

Next, update apt, and install Node:

sudo apt update
sudo apt install -y nodejs
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
sudo apt-get update && sudo apt-get install yarn
Enter fullscreen mode Exit fullscreen mode

Top comments (0)